Negative 32 bit conversion
criss87
Junior Member
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...
Comments
-
When you say 'display' do you mean on a touch panel or are you referring to using the value in a calculation? There are obviously ways but a little more info would help.
-
Thanks for the reply, I just need to store the negative value into a variable and of then sow on the touch panel.
The problem is just the conversion of the number from FFFFFFFFFFFFFA10 to -1520.
Criss -
Thanks for the reply, I just need to store the negative value into a variable and of then sow on the touch panel.
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 -
In what format is 0xFFFFFFFFFFFFFA10 equivalent to decimal -1520?
edit:
My bad, two's compliment *facepalm*. -
So with the above in mind your conversion is going to be a two step process. First you need to pass that character array into a single value with all the bits in the right place. If its always going to be contained in your lower 4 bytes you can use the function in the NCL math library. This will make it a bit easier as you can pass that into a single long for the next step.
Lets say you pass this into the variable x:x = math_raw_be_to_long(<you're four character array>)
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:decimalVal = (x - 1) ^ $FFFFFFFF
.
Alternatively, if it always only going to be 2 bytes with the value the following will work:value = ((yourData[1] << 8 + yourData[2]) - 1) ^ $FFFF
-
Thanks PhreaK! this will help me a lot!
Criss
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums