LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert signed hex string to a negative integer

I am communicating with a positioner.  In some commands, I am sending it two angles (pan and tilt) that can have both positive and negative values.  Each angle is passed as a 24-bit integer.  These integers are passed and received as a signed two's complement little endian integer split between multiple individual bytes.  I am able to convert the integers using the Pan and Tilt Angles.vi I have attached.  I have another vi that will convert the hex string back to a positive integer correctly but I am stumped about how to get the negative integers to come out right.  That vi is called Get Pan and Tilt Angles.vi. 

 

Thanks for any kind of help!

Download All
0 Kudos
Message 1 of 5
(7,590 Views)

Well, you could do everything that you're doing with byte arrays, indexing arrays, and building arrays,   ....  or .... you could simply use the Flatten To String function.

 

Side-Note: Index Array can be resized so you don't need to have 3 separate Index Array functions. 

Message Edited by smercurio_fc on 01-22-2009 10:51 AM
Message 2 of 5
(7,581 Views)

Thank you.  I like seeing different ways to do things and having less clutter on my block diagram definitely makes me happy.  I have only been using Labview for about 6 months now so I still have a lot to learn.

 

My main problem that makes me want to throw my computer out the window is converting hex string back to the integer so if anyone could help me get that one I would be extremely greatful!

0 Kudos
Message 3 of 5
(7,575 Views)

Sorry about that. Got side-tracked by work, and could only post the first part of the solution. You almost have the other direction. The problem is that you're missing a byte. You need to add FF or 00 depending on whether you have a positive of negative number. Like this:

 

Note that you can essentially do the same thing using the Unflatten From String function, but in this case it won't make much difference in terms of the amount of code. 

Message Edited by smercurio_fc on 01-22-2009 11:10 AM
Message 4 of 5
(7,572 Views)
Thank you SOOOO much!  You have saved my sanity!
0 Kudos
Message 5 of 5
(7,566 Views)