LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Weird behavior of unsigned int 32

Hello Great Minds,
 
I have been trying to construct a 32-bit word using the formula node and I am getting some weird output. Here's the deal:
 
I have U32 input and output in a formula node. Let's  say in the input and out is the output. In the formula node, code is like this.
 
out = in&255;
 
Now, if the 32-bit of in is not set, the  I get the right output but if it is I get 0xff. I don't know what's happening. Please help me out.
 
I have attached the code if you want to run a quick test.
 
Muchas Gracias,
 
Ananda
0 Kudos
Message 1 of 12
(4,416 Views)

This seems to be a bug in the formula node under LabVIEW 7.1. It works fine in LabVIEW 8.0.

Of course it seems to be a bit of an overkill to use the formula node for this, just use plain boolean AND operation and it will work as expected ;).

Message Edited by altenbach on 12-18-2005 02:35 PM

Download All
Message 2 of 12
(4,414 Views)
This is part of long bit-shifting, bit-adding, removing operation I have to do. Since, this was the crux of the problem, I thought i would ask for expert advice. If this is really a LabView bug, I would be happy that  the five hours I wasted was not because I was stupid. Smiley Happy
 
Thanks for your time though.
 
Ananda
0 Kudos
Message 3 of 12
(4,408 Views)
Even complex bit-twiddling operations are quite nice and efficient to implement without formula node, you just need to get the hang of it :o. I doubt you win any speed using the formula node (just guessing, of course).
 
Have a look at the entries of the first coding challenge from back in 2002 . 😉
Message 4 of 12
(4,403 Views)

Thanks for that link. It's very interesting and useful.

Ananda

0 Kudos
Message 5 of 12
(4,369 Views)

Man, this has been driving me nuts.  I'd like to use a formula node to do bit manipulation on U32 values that are being peeked from and poked back into 32-bit registers.  What I find is that, if I ever do either "bitwise and" (&) or the "bitwise or" (|), if the most significant bit of the right side of the expression is 1, then the output of the expression is always zero.  Some examples:

 

0xFFFFFFFF & 0x7FFFFFFF = 0x7FFFFFFF
0xFFFFFFFF & 0x80000000 = 0x00000000

0x00000000 | 0x7FFFFFFF = 0x7FFFFFFF
0xFFFFFFFF | 0x80000000 = 0x00000000

 

   Apparently, this is a bug I can demonstrate in LabView 8.5 and 8.6.  The same operation on a diagram seems to work as expected.  It just would have been nicer to use a formula node, since it's more straightforward when doing even slightly elaborate bit-banging.

 

-Mark

Message 6 of 12
(3,933 Views)

Post a VI that demonstrates this and have the values saved in the controls as the default.

 

I tried using LV 8.6.1 and did not see a problem.

0 Kudos
Message 7 of 12
(3,905 Views)

This vi will demonstrate the difference between bitwise and/or in a formula node vs in a diagram.  Basically, given a U32 "n" and a U32 hard-coded constant "p", if the most significant bit of "p" is set, the result of a either bitwise-or or bitwise-and of "n" is 0 when done in a formula node.  Geez it's hard to word that clearly for some reason.  😄

 

-Mark

0 Kudos
Message 8 of 12
(3,902 Views)

BTW, I get the same behavior in 8.5 (this machine) and 8.6 (my lab machine).  Please tell me I've overlooked something really dumb.  -M

 

0 Kudos
Message 9 of 12
(3,901 Views)

Something very odd about that.  I am posting an expanded version of what you did and experimented with different methods and datatypes.

 

All I can say is that I found two work arounds.

1.  Pass the constant in through an input connector which was done in the original post and thus why I said it worked fine for me in LV 8.6

2.  Don't list the constant as hex but put it in as a decimal number.

 

There are probably a lot more combinations of things to try to truly search out the extent of this and to see if it truly is a bug.

1.  Play with signed vs. unsigned datatypes some more

2.  Play with OR vs. AND vs. other boolean operations.

3.  Play with other integer representations such as 8 bit and 16 bit.

Message Edited by Ravens Fan on 04-16-2009 09:42 PM
Message 10 of 12
(3,885 Views)