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
Revision 5:3849b0d9fcf8, committed 2021-01-04
- Comitter:
- KINU
- Date:
- Mon Jan 04 02:45:03 2021 +0000
- Parent:
- 4:9fefb9f18f08
- Commit message:
- lll
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Dec 24 18:04:01 2020 +0000
+++ b/main.cpp Mon Jan 04 02:45:03 2021 +0000
@@ -3,46 +3,49 @@
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;
+
+ #include <stdio.h>
+ int Integer_N = 0;
+ int Fractional_N = 0;
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;
+
+void binary(int a){ //小数部分
+ if(a == Fractional_N){
+ for(int i=0;Fractional_N>0;i++){
+ decbin[i] = Fractional_N % 2;
+ Fractional_N = Fractional_N / 2;
+ }
+ printf(" 小数部の2進数 = ");
+ int l = 15;
+ while( l>0 ){
+ printf("%d", decbin[--l]);/* 2進数の出力 */
+ }
+ }else{
+ for(int i=0;Integer_N >0;i++){
+ intbin[i] = Integer_N % 2;
+ Integer_N = Integer_N / 2;
+ }
+ printf(" 整数部の2進数 = ");
+
+ int k = 8;
+ while( k>0 ){
+ printf("%d", intbin[--k]);
}
+ }
+ }
+int main(void){
+ /* 変数の宣言 */
+ float num = 435797271; //calsatから受け取った10進数のデータ
+ double n = num * 2 / 19.68; //変換式
+ Integer_N = (int)n; //
+ Fractional_N = (n - Integer_N)*32768;
- /* 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]);
- }
+ binary(Fractional_N);
+ binary(Integer_N);
+
+
printf("\n");
return 0;
}
-
-
-
\ No newline at end of file