LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

help in IEEE Floating Point Number Conversion

hi all

I have a query related to decimal fraction conversions to signed binary representation and vice versa...in simple words i want to convert -4.56 to binary (and vice versa) which would be something like 100101.1010110 with appropriate signed convention.

My question is :
Does LabVIEW provides some inbuilt vi for this purpose.I tried to convert a decimal fraction to binary (and vice versa) but it truncates the fractional part and considers only the integer part.....i.e.  of "34.56" only 34 gets converted.
 
If the answer is yes that would be absolutely wonderful if not (alas!) could somebody help me with this...i mean if somebody has already faced this problem and has come up with a solution.
Though i am working on the following convention (please go through the link if u like to else the relevant information is copied and pasted)

http://www.pwalsh.net/cs/Fractions.htm
http://www.pwalsh.net/cs/ASPCode/floatingNumber/floatingNumber.asp

-----------------------------------------------------------------------------------

IEEE Floating Point Number Convertion

-2.56

Your answer :

The whole part of the number in Base 10 is: 2
The decimal part of the number in Base 10 is: 0.56
To Calculate the decimal part in Base 2 we must repeatedly multiply it by 2.
0.56 * 2 = 1.12
0.12 * 2 = 0.24
0.24 * 2 = 0.48
0.48 * 2 = 0.96
0.96 * 2 = 1.92
0.92 * 2 = 1.84
0.84 * 2 = 1.68
0.68 * 2 = 1.36
0.36 * 2 = 0.72
0.72 * 2 = 1.44
0.44 * 2 = 0.88
0.88 * 2 = 1.76
0.76 * 2 = 1.52
0.52 * 2 = 1.04
0.04 * 2 = 0.08
0.08 * 2 = 0.16
0.16 * 2 = 0.32
0.32 * 2 = 0.64
0.64 * 2 = 1.28
0.28 * 2 = 0.56
0.56 * 2 = 1.12
0.12 * 2 = 0.24
0.24 * 2 = 0.48
0.48 * 2 = 0.96
The decimal part of the number in Base 2 is: .100011110101110000101000
The whole part of the number in Base 2 is: 10
Putting these together we get: 10.100011110101110000101000
Moving the decimal point to the right of the leftmost 1 the exponent in Base 10 is: 1
The exponent in two's complement format, with bias of 127 is: 10000000
Adjusting the mantissa we get: 01000111101011100001010

The correct result is 1|10000000|01000111101011100001010

-----------------------------------------------------------------------------------
thank you
Amit Jain
0 Kudos
Message 1 of 12
(5,258 Views)
Just typecast your SGL to a U32 or vice versa. 🙂
 
(The U32 indicator is set to display in binary with 32 digits, padded with leading zeroes)

Message Edited by altenbach on 02-02-2007 10:39 AM

Message 2 of 12
(5,253 Views)
Hi

thanks ...that was really good .... Robot Happy
can u suggest me something as a quick reference so that i can overcome most of problems like theseRobot Very Happy

thank you again
amit


0 Kudos
Message 3 of 12
(5,235 Views)
 
A quick reference on memory data storage can be found in the online help or here:
You should also know that LabVIEW is Big Endian and uses standard IEEE floating point representation. A good summary can be found on Wikipedia:
Check also the LabVIEW help on:
Message 4 of 12
(5,223 Views)

u seem to be a bank of knowledgeSmiley Surprised
Thanks a lot for ur help...Robot Happy

0 Kudos
Message 5 of 12
(5,203 Views)
congrats on 5000 posts i juts found out that
 
0 Kudos
Message 6 of 12
(5,199 Views)
Hi

one more question.....i need to XOR two binary numbers "represented in ieee 754 format"  ....I think i need to bring the two binary nos in the same exponent to Xor them(correct??).
My problem is that how do i build them in LabVIEW??I tried but couldnt do it using  the tips that u gave me previously.

Thank you
Amit Jain
0 Kudos
Message 7 of 12
(5,171 Views)
Hi Amitjain,

Can you please further explain what you are trying to do?  Are you not trying to do a bit by bit XOR of the entire number?  When I performed the XOR in LabVIEW, it XOR each bit and the numbers were padded with leading zeros. 
Regards,
Ching P.
DAQ and Academic Hardware R&D
National Instruments
0 Kudos
Message 8 of 12
(5,142 Views)
A bitwise XOR in LabVIEW is only defined for integers. Are you trying to do this for floating point numbers? What's the purpose? 😉
0 Kudos
Message 9 of 12
(5,137 Views)
Hi

Thanks for replying. Yes i need to XOr two binary nos. for increased accuracy in my application......Is there some way to do it?i guess if i could bring those two nos in same exponent i can perform Xor opeartion on them,just like adding where one needs to bring them in the same exponent.....
i think if its not possible in labview then may be we can convert the fractional binary nos in strings and then maniplate them to bring in the same exponent.But this will indeed increase the calculation overhead...thats the reason why i am looking out for a faster method and most preferably some inbuilt system in labview.
Guess may be some experienced guys like u can help me out.

Thank you
Amit Jain
0 Kudos
Message 10 of 12
(5,127 Views)