LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

decimal to hexadecimal conversion

I'm trying to send a hexadecimal number via the serial port and need to convert a decimal number to a hexadecimal number for this purpose. For example, I need to convert a number 20 to a string 14 when the hexadecimal display option is selected, not 3134, which is the HEX ASCII equivalent of 14 and which I currently get using the decimal to hexadecimal string conversion vi.

Thanks.
0 Kudos
Message 1 of 9
(3,961 Views)
Use the "Number To Hexadecimal String" primitive in your String>>String/Number Conversion palette.
0 Kudos
Message 2 of 9
(3,959 Views)
You need to use typecast, see attached code example image.
0 Kudos
Message 3 of 9
(3,959 Views)
S F wrote in news:50650000000800000000E10000-
1079395200000@exchange.ni.com:

> I'm trying to send a hexadecimal number via the serial port and need
> to convert a decimal number to a hexadecimal number for this purpose.
> For example, I need to convert a number 20 to a string 14 when the
> hexadecimal display option is selected, not 3134, which is the HEX
> ASCII equivalent of 14 and which I currently get using the decimal to
> hexadecimal string conversion vi.

I think you are looking for the "Byte array To String" function.

Function palette->String->String/Array/Path Conversion/Byte array To String


--
Rolf
0 Kudos
Message 4 of 9
(3,959 Views)
I think this is what you want. Use Number to hexadecimal string and then input it to this diagram. I'm not sure if I did the attachment right so I'll explain. It assumes your hex is 2 digit numbers, so it takes the first 2 digits, multiplies the first by 16 and adds the second, puts the result in an array and does the same for the rest of the pairs of digits. Then converts the array back to string at the end.
0 Kudos
Message 5 of 9
(3,959 Views)
Hmm. I always do things the hard way. Try using flatten to string.vi in the data manipulation pallette. Input should be as an 8 bit integer for output to be as 2 digit hex values.
0 Kudos
Message 6 of 9
(3,959 Views)
arussell wrote:

> I think this is what you want. Use Number to hexadecimal string and
> then input it to this diagram. I'm not sure if I did the attachment
> right so I'll explain. It assumes your hex is 2 digit numbers, so it
> takes the first 2 digits, multiplies the first by 16 and adds the
> second, puts the result in an array and does the same for the rest of
> the pairs of digits. Then converts the array back to string at the
> end.
>
>
> ------------------------------------------------------------------------
>

Wow! What a runaround. Why post this suggestion? The answer
was given by "altenbach" 2 posts ago using only 1 function -
typcast. Simple and sweet...

--
Michael Aivaliotis
http://mmwis.com
http://forums.lavausergroup
.org
http://niweekblog.com


Michael Aivaliotis
VI Shots LLC
0 Kudos
Message 7 of 9
(3,959 Views)
Hello
I was trying to send a number over the serial port. The way I wnated is first convert the number whose max could be 65535 and convert it to Hex and split the Hex value to two parts and send the first two letters first and then the second two letters. My device can only take values up to FF in the buffer that is why i am splitting a hex value into two. With this configuration, I tried putting a constant string in Hex Display mode and it works fine. When i try with number converted and split apart then i get totally different values in my device, Could someone please look at my problem and suggest a way,
I have attached the connections, I have a stacked sequence first one sends the first two and second one the rest.
Thank you very much
0 Kudos
Message 8 of 9
(3,439 Views)
cross post!

Message Edited by GerdW on 06-25-2007 09:38 AM

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 9
(3,431 Views)