09-02-2009 01:59 PM
Solved! Go to Solution.
09-02-2009 02:41 PM - edited 09-02-2009 02:43 PM
Why are you wanting to convert it?
Hex and binary are formats for integers only, not for doubles and floats.
1) internal use? there is no need to do this as an integer is an integer is an integer.
2) printf statements? Use the proper modifier.
3) GUI display? Change the integer format in the GUI editor or the attribute in real time.
4) something else? please give us more detail.
09-02-2009 02:57 PM
Hi,
What I want to know is there a solution in Labwindow CVI (9.01) to convert a real number (can be negative number, e.g., -123.96) to 32 bit binary? any help would be appreciated.
09-02-2009 03:00 PM
thieny1:
CVI doesn't have anything built in, but there are at lot of different ways to do it. Look at this post which includes my example Convert2.zip.
http://forums.ni.com/ni/board/message?board.id=180&message.id=42460&query.id=311972#M42460
If you search this forum for binary, convert to binary, binary conversion, etc. you will find a long list of answered questions.
09-02-2009 06:15 PM
thieny:
Sorry I missed part of your original question. The project I pointed you to in my first post only works for integers.
If you want to see all the 1's and 0's as they are stored in memory, you are looking at the IEEE floating point format.
Here's a nice tool that displays the fields as they are packed into the IEEE format.
http://babbage.cs.qc.cuny.edu/IEEE-754/Decimal.html
Here's a detailed wikipedia article on float point.
http://en.wikipedia.org/wiki/Floating_point#Internal_representation
The code needed to display the 1's and 0's is not that complicated. You can use casting and pointer arithmetic to walk through the floating point number as it's stored in memory byte by byte.
I attached a sample project that does that. It displays the output as binary or hex strings. As scomack said, if you want to use it as a number, you don't need to convert it: it is already a number.
If you want to directly manipulate the IEEE value as stored in memory, you can still cast it byte by byte and manipulate each byte. I have no idea why you want to do this, since the compiler manages the IEEE format fine on its own, but you could.
09-03-2009 01:03 PM
Dear AI S,
Thanks for your info. This will work.