07-29-2024 09:39 AM
Hi everyone,
I am working on a data where 1bit is sign bit and 2bit uncare bit.
I am getting correct result for positive numbers but for negative numbers , I am unable to match the raw value with calculated value .
Following is my data:
If Raw value converted from binary to decimal is 256
then , i right shift by 2 and multiply by my scaling factor to get desired result in case number is positive.
Scaling Factor : 0.01953125
Postive Numbers working fine
256 1.25
244 1.1914
184 0.8984
64 0.3125
Negative Numbers :
4083 ( Raw Value ) : expected -0.0781
3955 : -0.7031
3943 : -0.7617
3951: -0.7227
4059: -0.1953
I have also attached a excel file, can anyone help me understand what am I missing .
Thanks in advance.
Solved! Go to Solution.
07-29-2024 10:37 AM
An excel file is pretty useless t troubleshoot this:
What is the dataype of the "raw" values, for example? Why not attach an actual VI that has your raw values as diagram constants?
07-29-2024 10:47 AM - edited 07-29-2024 10:57 AM
Make sure the input is I16, then left shift (logical shift) by four followed by an arithmetic shift by -6 (scale by power of two)
07-29-2024 03:26 PM
Thankyou so much..
Tried multiple methods like two's complement , went as far as looking into ieee754 floating point conversion.
Can you let me know,what theory is being this logic ?
07-29-2024 03:47 PM
You seem to have 12bit signed integers, thus the sign but is in the wrong place for I16. Shifting left places the sign bit in the first position of I16 and the arithmetic shift right by six bits (undoes the earlier 4 bit shift and applies your 2 bit shift in addition).
(Of course you could just do a left shift by 4 bits to get a signed I16 and then multiply by a better scaled constant that already accounts for the 6 bit shift).