LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

changing HEX into a number

why doesn't this vi work? i am receiving 3 hex bytes from a board, and i need to view it as a numerical value. i know that the hex "F9FFFF" is equal to 16,383999 when i look at it on the calculator.
 
i receive 3 bytes, convert it to a number, and display it. it seems like a simple task.......
 
thanks,,,,
 
im using labview 7.0
0 Kudos
Message 1 of 17
(3,830 Views)

Just yesterday somebody posted another question kinda like this, the solution of which involved a nifty use of the Type Cast function.  Turns out that function can help you out too.  Check out the attached VI (saved in LabVIEW 8.0).  Screenshot is below in case you don't have 8.0.

Hope this helps,

-D

Message Edited by Darren on 02-02-2006 07:08 PM

Download All
Message 2 of 17
(3,825 Views)


NewMachine a écrit:
why doesn't this vi work? i am receiving 3 hex bytes from a board, and i need to view it as a numerical value. i know that the hex "F9FFFF" is equal to 16,383999 when i look at it on the calculator.


Darren's solution is of course perfect, but he didn't reply to your question.
You said you received 3 bytes. In your vi, you process an ascii string, recovering the first 3 chars (not bytes !..), then you convert this substring into a single byte (the constant you wired to the Hex String To Number bottom input is an U8 !..). There are 2 confusions here : one is that the string input of the HSTN function should have been 6 digits long since, as explained in the help, it "interprets the characters 0 through 9, A through F, [...] as a hex integer and returns it in number. The second is that you should have wired an U32 or I32 as numeric input.
Chilly Charly    (aka CC)
Message 3 of 17
(3,818 Views)

Yeah yeah, so I sorta skimmed the original post.  All I really saw was "F9FFFF" and "16383999" and I started coding.  Turns out I love numbers almost as much as I love LabVIEW.  🙂

-D

Message Edited by Darren on 02-02-2006 08:38 PM

Message 4 of 17
(3,810 Views)
[IFK_STR_HexBytes2Num]
 
Automatically pads the input "Hex Bytes" to 4 bytes and converts to its "Numerical" representation.
 
LabVIEW 7.1
Solution Prepared By,
Ian Fung, Koo | Sg
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 5 of 17
(3,806 Views)
i have labview 7.0 - is there a way to convert it so i can see this example? thanks....
0 Kudos
Message 6 of 17
(3,784 Views)
 

You said you received 3 bytes. In your vi, you process an ascii string, recovering the first 3 chars (not bytes !..),
 
-------------------------------------------------------------
but i was told when i use a string subset function and the input is hex code it reads two characters at a time, for one byte. i know it is coming back as hex from the board because when i put an indicator down....it is hex that is displayed.
 
i made both of the changes as suggested by you below and then type in F9FFFF and am returned 0. what should i do?
 
thanks.....
samantha
-------------------------------------------------------------
 
 then you convert this substring into a single byte (the constant you wired to the Hex String To Number bottom input is an U8 !..). There are 2 confusions here : one is that the string input of the HSTN function should have been 6 digits long since, as explained in the help, it "interprets the characters 0 through 9, A through F, [...] as a hex integer and returns it in number. The second is that you should have wired an U32 or I32 as numeric input.



0 Kudos
Message 7 of 17
(3,785 Views)

and what if i want to convert more or less than 3 bytes? i have one stupid byte that i try to convert using something like the attached vi...and it it doesn't return anything correct

 

please help

Message Edited by NewMachine on 02-03-2006 03:55 PM

Message Edited by NewMachine on 02-03-2006 03:55 PM

0 Kudos
Message 8 of 17
(3,791 Views)
my apologies... here is the LV7 version
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 9 of 17
(3,769 Views)

Hi NewMachine,

You can use a clever trick with the Concatenate Strings function to append a variable number of pad bytes on the beginning of your string, depending on its length.  Here is a screenshot of a VI that does this...it will pad the appropriate number of bytes onto the beginning of the string, so you can have 0, 1, 2, 3, or 4 bytes of hex in your string, and the value will always be converted appropriately.

Hope this helps,

-D

Message Edited by Darren on 02-03-2006 09:58 PM

Message 10 of 17
(3,764 Views)