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@4:9fefb9f18f08, 2020-12-24 (annotated)
- Committer:
- KINU
- Date:
- Thu Dec 24 18:04:01 2020 +0000
- Revision:
- 4:9fefb9f18f08
- Parent:
- 3:1883ea70d247
- Child:
- 5:3849b0d9fcf8
kkk
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ryouheitakamoto | 0:303ad425d2ac | 1 | #include "mbed.h" |
| ryouheitakamoto | 0:303ad425d2ac | 2 | |
| KINU | 1:03cb3b25065c | 3 | Serial pc(SERIAL_TX, SERIAL_RX); |
| KINU | 1:03cb3b25065c | 4 | Serial device(PA_9,PA_10); |
| KINU | 3:1883ea70d247 | 5 | |
| KINU | 3:1883ea70d247 | 6 | int main(void) |
| KINU | 2:98f6cc48ca3a | 7 | { |
| KINU | 3:1883ea70d247 | 8 | /* 変数の宣言 */ |
| KINU | 4:9fefb9f18f08 | 9 | float num = 154.243; //calsatから受け取った10進数のデータ |
| KINU | 4:9fefb9f18f08 | 10 | float n = num * 2 / 19.68; //変換式 |
| KINU | 4:9fefb9f18f08 | 11 | int Integer_N = (int)n; // |
| KINU | 4:9fefb9f18f08 | 12 | int Fractional_N = (n - (int)n)*32768; |
| KINU | 3:1883ea70d247 | 13 | int i; |
| KINU | 4:9fefb9f18f08 | 14 | int intbin[7]={0}; |
| KINU | 4:9fefb9f18f08 | 15 | int decbin[14]={0}; |
| KINU | 4:9fefb9f18f08 | 16 | |
| KINU | 3:1883ea70d247 | 17 | |
| KINU | 4:9fefb9f18f08 | 18 | /* 小数部 10進数→2進数の変換 */ |
| KINU | 4:9fefb9f18f08 | 19 | int intdec = Fractional_N * 100; |
| KINU | 4:9fefb9f18f08 | 20 | for(i=0;intdec>0;i++){ |
| KINU | 4:9fefb9f18f08 | 21 | decbin[i] = Fractional_N % 2; |
| KINU | 4:9fefb9f18f08 | 22 | Fractional_N = Fractional_N / 2; |
| KINU | 4:9fefb9f18f08 | 23 | } |
| KINU | 4:9fefb9f18f08 | 24 | /*整数部 10進数→2進数の変換 */ |
| KINU | 4:9fefb9f18f08 | 25 | for(i=0;Integer_N >0;i++){ |
| KINU | 4:9fefb9f18f08 | 26 | intbin[i] = Integer_N % 2; |
| KINU | 4:9fefb9f18f08 | 27 | Integer_N = Integer_N / 2; |
| KINU | 3:1883ea70d247 | 28 | } |
| KINU | 3:1883ea70d247 | 29 | |
| KINU | 3:1883ea70d247 | 30 | /* 2進数の出力 */ |
| KINU | 4:9fefb9f18f08 | 31 | printf(" 整数部の2進数 = "); |
| KINU | 3:1883ea70d247 | 32 | int k = 8; |
| KINU | 3:1883ea70d247 | 33 | while( k>0 ){ |
| KINU | 4:9fefb9f18f08 | 34 | printf("%d", intbin[--k]); |
| KINU | 4:9fefb9f18f08 | 35 | } |
| KINU | 4:9fefb9f18f08 | 36 | printf("\n"); |
| KINU | 4:9fefb9f18f08 | 37 | printf(" 小数部の2進数 = "); |
| KINU | 4:9fefb9f18f08 | 38 | int l = 15; |
| KINU | 4:9fefb9f18f08 | 39 | while( l>0 ){ |
| KINU | 4:9fefb9f18f08 | 40 | printf("%d", decbin[--l]); |
| KINU | 3:1883ea70d247 | 41 | } |
| KINU | 3:1883ea70d247 | 42 | printf("\n"); |
| KINU | 3:1883ea70d247 | 43 | |
| KINU | 3:1883ea70d247 | 44 | return 0; |
| KINU | 2:98f6cc48ca3a | 45 | } |
| KINU | 2:98f6cc48ca3a | 46 | |
| KINU | 2:98f6cc48ca3a | 47 | |
| KINU | 2:98f6cc48ca3a | 48 |