I am trying to convert a float value to a 4-byte hexadecimal value.
For example my input is: 58.5. My expected output is: 426A0000 or like 0x42 0x6A 0x00 0x00.
My program is:
void setup() {
Serial.begin(9600);
float z = 128;
unsigned i;
unsigned char *chpt;
chpt = (unsigned char *)&z;
Serial.print("Float Value : ");
Serial.println(z);
Serial.print("4 Byte hexadecimal Value: ");
for (i = 0; i < sizeof(z); i++) {
Serial.print(chpt[i],HEX);
//Serial.print(" ");
}
Serial.println();
}
void loop() {
}
My current output is:
Float Value : 128.00
4 Byte hexadecimal Value: 00043