doppler shift / Mbed 2 deprecated 7021ver2

Dependencies:   mbed

Files at this revision

API Documentation at this revision

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