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@5:3849b0d9fcf8, 2021-01-04 (annotated)
- Committer:
- KINU
- Date:
- Mon Jan 04 02:45:03 2021 +0000
- Revision:
- 5:3849b0d9fcf8
- Parent:
- 4:9fefb9f18f08
lll
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 | 5:3849b0d9fcf8 | 6 | |
| KINU | 5:3849b0d9fcf8 | 7 | #include <stdio.h> |
| KINU | 5:3849b0d9fcf8 | 8 | int Integer_N = 0; |
| KINU | 5:3849b0d9fcf8 | 9 | int Fractional_N = 0; |
| KINU | 4:9fefb9f18f08 | 10 | int intbin[7]={0}; |
| KINU | 4:9fefb9f18f08 | 11 | int decbin[14]={0}; |
| KINU | 5:3849b0d9fcf8 | 12 | |
| KINU | 5:3849b0d9fcf8 | 13 | void binary(int a){ //小数部分 |
| KINU | 5:3849b0d9fcf8 | 14 | if(a == Fractional_N){ |
| KINU | 5:3849b0d9fcf8 | 15 | for(int i=0;Fractional_N>0;i++){ |
| KINU | 5:3849b0d9fcf8 | 16 | decbin[i] = Fractional_N % 2; |
| KINU | 5:3849b0d9fcf8 | 17 | Fractional_N = Fractional_N / 2; |
| KINU | 5:3849b0d9fcf8 | 18 | } |
| KINU | 5:3849b0d9fcf8 | 19 | printf(" 小数部の2進数 = "); |
| KINU | 5:3849b0d9fcf8 | 20 | int l = 15; |
| KINU | 5:3849b0d9fcf8 | 21 | while( l>0 ){ |
| KINU | 5:3849b0d9fcf8 | 22 | printf("%d", decbin[--l]);/* 2進数の出力 */ |
| KINU | 5:3849b0d9fcf8 | 23 | } |
| KINU | 5:3849b0d9fcf8 | 24 | }else{ |
| KINU | 5:3849b0d9fcf8 | 25 | for(int i=0;Integer_N >0;i++){ |
| KINU | 5:3849b0d9fcf8 | 26 | intbin[i] = Integer_N % 2; |
| KINU | 5:3849b0d9fcf8 | 27 | Integer_N = Integer_N / 2; |
| KINU | 5:3849b0d9fcf8 | 28 | } |
| KINU | 5:3849b0d9fcf8 | 29 | printf(" 整数部の2進数 = "); |
| KINU | 5:3849b0d9fcf8 | 30 | |
| KINU | 5:3849b0d9fcf8 | 31 | int k = 8; |
| KINU | 5:3849b0d9fcf8 | 32 | while( k>0 ){ |
| KINU | 5:3849b0d9fcf8 | 33 | printf("%d", intbin[--k]); |
| KINU | 3:1883ea70d247 | 34 | } |
| KINU | 5:3849b0d9fcf8 | 35 | } |
| KINU | 5:3849b0d9fcf8 | 36 | } |
| KINU | 5:3849b0d9fcf8 | 37 | int main(void){ |
| KINU | 5:3849b0d9fcf8 | 38 | /* 変数の宣言 */ |
| KINU | 5:3849b0d9fcf8 | 39 | float num = 435797271; //calsatから受け取った10進数のデータ |
| KINU | 5:3849b0d9fcf8 | 40 | double n = num * 2 / 19.68; //変換式 |
| KINU | 5:3849b0d9fcf8 | 41 | Integer_N = (int)n; // |
| KINU | 5:3849b0d9fcf8 | 42 | Fractional_N = (n - Integer_N)*32768; |
| KINU | 3:1883ea70d247 | 43 | |
| KINU | 5:3849b0d9fcf8 | 44 | binary(Fractional_N); |
| KINU | 5:3849b0d9fcf8 | 45 | binary(Integer_N); |
| KINU | 5:3849b0d9fcf8 | 46 | |
| KINU | 5:3849b0d9fcf8 | 47 | |
| KINU | 3:1883ea70d247 | 48 | printf("\n"); |
| KINU | 3:1883ea70d247 | 49 | |
| KINU | 3:1883ea70d247 | 50 | return 0; |
| KINU | 2:98f6cc48ca3a | 51 | } |