Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------
- void setup() {
- Serial.begin(9600);
- //------------------------------------------------ Float to array
- float z = 22.55;
- unsigned char *chpt;
- chpt = (unsigned char *)&z;
- Serial.print("float : ");
- Serial.println(z);
- Serial.print(" Hex : ");
- for (int i = 0; i < sizeof(z); i++) {
- Serial.print("0x");
- Serial.print(chpt[i], HEX);
- Serial.print(" ");
- }
- Serial.println();
- //------------------------------------------------ Array to float
- union {
- char c[4];
- float f;
- } u;
- for (int i = 3; i > -1; i--)
- {
- u.c[i] = chpt[i];
- }
- Serial.print("float : "); Serial.println( u.f);
- }
- //------------------------------------------------
- void loop() {
- // put your main code here, to run repeatedly:
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement