Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
- Committer:
- KINU
- Date:
- 2020-12-24
- Revision:
- 4:9fefb9f18f08
- Parent:
- 3:1883ea70d247
- Child:
- 5:3849b0d9fcf8
File content as of revision 4:9fefb9f18f08:
#include "mbed.h"
Serial pc(SERIAL_TX, SERIAL_RX);
Serial device(PA_9,PA_10);
int main(void)
{
/* 変数の宣言 */
float num = 154.243; //calsatから受け取った10進数のデータ
float n = num * 2 / 19.68; //変換式
int Integer_N = (int)n; //
int Fractional_N = (n - (int)n)*32768;
int i;
int intbin[7]={0};
int decbin[14]={0};
/* 小数部 10進数→2進数の変換 */
int intdec = Fractional_N * 100;
for(i=0;intdec>0;i++){
decbin[i] = Fractional_N % 2;
Fractional_N = Fractional_N / 2;
}
/*整数部 10進数→2進数の変換 */
for(i=0;Integer_N >0;i++){
intbin[i] = Integer_N % 2;
Integer_N = Integer_N / 2;
}
/* 2進数の出力 */
printf(" 整数部の2進数 = ");
int k = 8;
while( k>0 ){
printf("%d", intbin[--k]);
}
printf("\n");
printf(" 小数部の2進数 = ");
int l = 15;
while( l>0 ){
printf("%d", decbin[--l]);
}
printf("\n");
return 0;
}