LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert a number to 32 bit binary or Hex

Solved!
Go to solution
Anyone know if LabWindow CVI has a function to convert a number: integer, real, double (can be negative) to binary and HEX? Or any sample code can do this conversion. Thanks
0 Kudos
Message 1 of 6
(8,303 Views)

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.

Message Edited by scomack on 09-02-2009 02:43 PM
0 Kudos
Message 2 of 6
(8,301 Views)

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.

0 Kudos
Message 3 of 6
(8,293 Views)

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.

0 Kudos
Message 4 of 6
(8,292 Views)

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.

Message 5 of 6
(8,286 Views)
Solution
Accepted by topic author thieny1

Dear AI S,

 

Thanks for your info. This will work.

0 Kudos
Message 6 of 6
(8,249 Views)