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
Diff: main.cpp
- Revision:
- 1:3d373c17be18
- Parent:
- 0:4eeab953c09c
- Child:
- 2:2a1eb5136f89
--- a/main.cpp Mon Dec 28 03:49:08 2020 +0000
+++ b/main.cpp Mon Dec 28 03:57:08 2020 +0000
@@ -12,6 +12,8 @@
int Decimal_data = 0;
double Dec = (data - Integer_data);
int i = 1;
+ int intbin[7]={0};
+ int decbin[14]={0};
while(1) {
@@ -23,6 +25,31 @@
}
printf("Integer_data = %d\r\nDecimal_data = %d\r\n",Integer_data,Decimal_data);
- return 0;
+
+ /* 小数部 10進数→2進数の変換 */
+ int intdec = Decimal_data * 100;
+ for(i=0;intdec>0;i++){
+ decbin[i] = Decimal_data % 2;
+ Decimal_data = Decimal_data / 2;
+ }
+ /*整数部 10進数→2進数の変換 */
+ for(i=0;Integer_data >0;i++){
+ intbin[i] = Integer_data % 2;
+ Integer_data = Integer_data / 2;
+ }
+
+ /* 2進数の出力 */
+ printf(" Bainary of Integer_data = ");
+ int k = 8;
+ while( k>0 ){
+ printf("%d", intbin[--k]);
+ }
+ printf("\n");
+ printf(" Bainary of Decimal_data = ");
+ int l = 15;
+ while( l>0 ){
+ printf("%d", decbin[--l]);
+ }
+ printf("\n");
}
\ No newline at end of file