LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary to Floating point numer

Solved!
Go to solution

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.

0 Kudos
Message 1 of 5
(364 Views)

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?

0 Kudos
Message 2 of 5
(336 Views)
Solution
Accepted by topic author divgup1986

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)

 

altenbach_0-1722268331028.png

 

 

Message 3 of 5
(330 Views)

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 ?

0 Kudos
Message 4 of 5
(272 Views)

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).

Message 5 of 5
(266 Views)