LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

int32 uint32 difference

Dear All,

 

I am reading modbus registers from a power (energy) meter.

The data type in the Datasheet of the meter for power feild is signed 32 and for voltage is unsigned 32.

The modbus registers are in unsigned 16 bit format.

When i convert the two register for voltage unsigned16 to Int32 (long Inverse) the values are correct, but when i do the same thing for Power then the values are not coming right.

 

Basically what is the differnece in converting 2 Unsigned 16 registers into Signed 32 and unsigned 32.

0 Kudos
Message 1 of 3
(4,336 Views)

Hi shrekt,

 

check.png

Does that answer your question?

Best regards,
GerdW


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

To more specifically answer your question (since a LabVIEW solution already appears above), a "signed" variable represents Positive and Negative values of a number.  While, on the other hand, an "unsigned" variable ONLY represents Positive values.

 

You may ask why this is the case.  Well the "32" in "int32" and "uint32" represents the number of bits (0 or 1 digits) used to represent the number in "computer language" -- binary code.

 

 

*Borrowing some of this math from Wikipedia since I don't have a calculator on me*

 

Since most computer science numbering starts with 0, there are 232 − 1 binary digits used to represent one of these integers.  For instance:  00001111000011110000111100001111 would represent one of the possible numbers.

 

If you used all of these combinations of 0's and 1's, you would have an Unsigned Integer with values ranging from 0 to 4,294,967,295 (which equals 232 − 1.)

 

However it is often nice to represent negative values, right?  So in order to do so, we cut the number of possible values in half (roughly) to make half of the possible combinations positive and half of them negative. 

 

(There are a few ways to go about this, but usually the very first digit is a "1" in a negative number.)

 

00001111000011110000111100001111 - positive

10001111000011110000111100001111 - negative

 

If you follow this type of interpreation of the binary digits, you will a Signed Integer with values ranging from −2,147,483,648 to 2,147,483,647 [from −(231) to 231 − 1].

 

Therefore you need to specify to LabVIEW how to interpret these numbers.

 

10001111000011110000111100001111 = 2400128783 in decimal using an Unsigned Integer 32


10001111000011110000111100001111 = -1894838513 in decimal using a Signed Integer 32 (2's complement formatting)

 

This is why you seem to be getting "correct" values for unsigned voltage, but the signed power seems to be wrong.  You need to specify which one you want in the code by "converting" ("casting" in textual languages) this number to a signed int 32.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 3 of 3
(4,325 Views)