LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Inverse of two's complement

Solved!
Go to solution

Hi I am trying to convert a U32 two's complement number back to a negative integer. 

Can someone guide me on this?

0 Kudos
Message 1 of 5
(181 Views)
Solution
Accepted by topic author Satvikpai

Hi Satvikpai,

 


@Satvikpai wrote:

Hi I am trying to convert a U32 two's complement number back to a negative integer. 

Can someone guide me on this?


An U32 is (as the name says) an UNSIGNED value, so it cannot be negative!

 

Maybe you want to convert the U32 value into an I32 value (using ToI32)?

Best regards,
GerdW


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

If you somehow got a signed integer stored in a U32 (read from a file to the wrong type?), you can use a type cast to convert it to I32:

U32 Twos Complement Conversion Example.png

0 Kudos
Message 3 of 5
(127 Views)

Hi JJohn,

 


@jjohn1 wrote:

you can use a type cast to convert it to I32:


ToI32 does the very same job - and (probably) more efficient and with less BD space…

Best regards,
GerdW


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

Thanks for the note onToI32.  I did not know how it would handle values with the sign bit set.  On a good day you learn something new.  Thanks!

0 Kudos
Message 5 of 5
(84 Views)