Search
 
SCRIPT & CODE EXAMPLE
 

C

Trasmettere variabile float attraverso seriale

float myFloat; // ho una var float
char *myBuffer; // ho un puntatore a char

// assegno il puntatore della var float al puntatore a char utilizzando il cast
myBuffer = (char *)(&myFloat);

// ora myBuffer punta al primo byte della variabile float
// usando la matematica dei puntatori ora posso leggere tutti e quattro i byte del float

dato = *myBuffer;  // leggo il primo byte
myBuffer++;         // punto al secondo byte

dato = *myBuffer;  // leggo il secondo byte
myBuffer++;         // punto al terzo byte

dato = *myBuffer;  // leggo il terzo byte
myBuffer++;         // punto al quarto byte

dato = *myBuffer;  // leggo il quarto byte

// per ricomporre il valore float basta fare il processo inverso
// scrivendo in myBuffer i vari byte.
Comment

PREVIOUS NEXT
Code Example
C :: C fgets() and puts() 
C :: /usr/bin/mandb: fopen /var/cache/man/7935: Permission denied 
C :: how to use arry 
C :: ? : em linguagem C 
C :: C How to use enums for flags? 
C :: comando para ejecutar hilos en c 
C :: can we use special characters in switch case in c 
C :: countoddevenDifference 
C :: params in main function in C 
C :: else if statement in c 
C :: how to write a hello world program in c 
C :: concate string in c 
C :: robtex 
Dart :: flutter delay 
Dart :: navigator.pushandremoveuntil flutter 
Dart :: flutter format currency fcfa 
Dart :: round container flutter 
Dart :: flutter how to space buttons evenly in a row 
Dart :: dart continue 
Dart :: How to add a circular dot as an indicator in Flutter Tabs? 
Dart :: how to get screen size in flutter 
Dart :: Floating Action Button rectangular shaped (round corners) 
Dart :: how to disable screen rotation in flutter 
Dart :: Send HTTP POST request in Flutter or Dart 
Dart :: flutter column vertical direction 
Dart :: throw error in dart 
Dart :: flutter main.dart 
Dart :: flutter chip 
Dart :: how to convert timestamp to datetime in dart 
Dart :: convert iso date string into date and time string flutter 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =