Negative 32 bit conversion
criss87
Posts: 32
Hi there,
To display a negative voltage from a device (that should be -15.20), I get from the device FA10
I have seen that hex FFFFFFFFFFFFFA10 is actually the presentation of -1520 but how to display -1520 ?
then convert to float is simple...
To display a negative voltage from a device (that should be -15.20), I get from the device FA10
I have seen that hex FFFFFFFFFFFFFA10 is actually the presentation of -1520 but how to display -1520 ?
then convert to float is simple...
0
Comments
The problem is just the conversion of the number from FFFFFFFFFFFFFA10 to -1520.
Criss
itoa or ftoa is what you need to convert an integer or float to a string to show on a touch panel. Any text on a touch panel has to be of char type.
Paul
edit:
My bad, two's compliment *facepalm*.
Lets say you pass this into the variable x:
This assumes that what came from the device was in fact "$FA, $10" - if its an ascii representation of it you'll have to convert that first as well.
Once you have that you need to do the conversion from two's compliment to straight up, normal, human readable decimal. To do that you first need to subtract 1 then flip all the bits: .
Alternatively, if it always only going to be 2 bytes with the value the following will work:
Criss