LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

24 bit 2's complement hex string to number

Solved!
Go to solution

i get a 24 bit 2's complement hex number in string format from serial port. i want use this hex number in continue in my LabVIEW code. but it doesn't work correctly !!

in example if i receive ffffff it is equal to -1 and if i receive 000001 it is equal to +1 .

anybody has solution for my problem ?

Thanks.

0 Kudos
Message 1 of 15
(5,763 Views)

See here.

0 Kudos
Message 2 of 15
(5,752 Views)

As JB's link doesn't work for me (right now as NI website seems to have its problems) I attach this snippet:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 15
(5,736 Views)

Thank you friends.

but finally i want a number that can be positive or negative. in fact i need number in DBL format with it's sign.

0 Kudos
Message 4 of 15
(5,733 Views)

Hi ajapyy,

 

an I32 is sufficient here as it also keeps the sign (and your "hex number" doesn't come with fractional digits).

You are free to convert the I32 to DBL later on…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 15
(5,731 Views)

That's a pretty clever sign extension, but a little difficult for me to wrap my brain around. An alternative to let LV do it for you would be to use a 24-bit fixed-point type for the conversion:

 

24BitHex.png

Message 6 of 15
(5,701 Views)
Solution
Accepted by topic author ajapyy

Hi JLewis,

 

get the sign bit, multiply it by 2*255 to fill the upper 8 bits of the I32, OR it with the remaining bits of the number…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 15
(5,698 Views)

JLewis a écrit :

That's a pretty clever sign extension, but a little difficult for me to wrap my brain around. An alternative to let LV do it for you would be to use a 24-bit fixed-point type for the conversion:

 

24BitHex.png


Very interesting ! This is the first time I see this solution.

0 Kudos
Message 8 of 15
(5,663 Views)

Hi All

I am trying to converter 4 bit hex string to number. I know the right results. But I do not know how converte. Please see the attached vi

Please help me.

Thanks

0 Kudos
Message 9 of 15
(5,515 Views)

Hi Hong,

 

please convert your VI to LV2011. Do you mind to write down some example numbers?

 

And what is a "4 bit hex string"?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 15
(5,511 Views)