LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Formula node bug or my code wrong?

Solved!
Go to solution

Hi i must use formula node to compute bit operation ,but when expression like c=a|b,when b is > 0x7fffffff ,the result is 0,but int16 is right,why?  tested in labview 2017(32) Chinese Simplified,and labview 2019 (32) Chinese Simplified in win7 .

Message 1 of 5
(2,934 Views)
Solution
Accepted by topic author gsm174

Probably a small inconsistency in the formula node where an int16 is internally extended to the full 32 bit register size anyways before doing the operators. For the int32 you basically have an overflow as the OR operator is done in the signed int32 space and then truncated when converted to the unsigned uInt32 space.

The formula node looks and smells like C but it isn't. It is only a subset of C and does generally work like C but isn't guaranteed to be exact C semantics. There are also syntactical differences to C such as the exponent operator. 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 5
(2,890 Views)

A U32 or I32 is 4 bytes, or in hex written as 8 hex numbers, in your text you're using 9. The code looks ok, but you're doing an operation between a I32 and a U32, so i assume there's a conversion going on. 7fff ffff is the biggest positive number a I32 can have, anything 'bigger' and it turns into a negative number. All 'f's (I32) is -1 if memory serves.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 5
(2,819 Views)

I think Mr. Rolfk's suggestion may be correct. This question is related to the word length of the internal conversion. I tried it again with I32 and U32, but the result is also incorrect. The following picture is the result of my experiment and the solution to the operation. Currently, I don't know if the same result is obtained in labview (64).U32 bit operation.png

0 Kudos
Message 4 of 5
(2,777 Views)

new opt.png

0 Kudos
Message 5 of 5
(2,772 Views)