LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error in case statement when using a U32?

When you wire unsigned integers into a case statement, they should accept all values up to the maximum according to the data type:  2^8 for U8, 2^16 for U16, 2^32 for U32, and 2^64 for U64.  However, for some reason the case statement doesn't accept all the values for a U32.  It only accepts values up to 2^31.  Am I missing something fundamental here?
 
What happens when I fill my case statement with 2 billion cases but still need more?  Smiley Wink
 
(Actually I have a device driver that returns 2^32 when an error occurs.  I work around the error by casting it to a U64 before doing the comparison, but I thought it was odd that it didn't work with a U32.)


Message Edited by Daklu on 11-09-2007 03:20 PM
0 Kudos
Message 1 of 11
(5,154 Views)
Interesting. This look like a bug...
 
Curiously, you can insert the toU64, enter the 2147483648, then delete the toU64 and things are ok until the next time you type in the selector field of the case structure. (See attached)
 
Odd....
0 Kudos
Message 2 of 11
(5,144 Views)
A case statement will take the max value of a U32, and you are incorrect about the max values. The max value for a U32 is 4294967295 which is (2^32)-1. The max value for a U8 is 255 (2^8)-1, etc.
0 Kudos
Message 3 of 11
(5,139 Views)
Yes, you are right about the minus 1.  The attached vi's reflect the correct number [ (2^n)-1 ] even though I wasn't clear in the original post.


Message Edited by Daklu on 11-09-2007 03:37 PM
0 Kudos
Message 4 of 11
(5,134 Views)


Dennis Knutson wrote:
A case statement will take the max value of a U32, and you are incorrect about the max values. The max value for a U32 is 4294967295 which is (2^32)-1. The max value for a U8 is 255 (2^8)-1, etc.


But it seems to fail already with (2^31), which is a legal U32 value. (the "max of I32"+1)
0 Kudos
Message 5 of 11
(5,132 Views)
I can't get it to fail. In the original post, the number in the case selector was a string. I just replaced it with a U32 (2147483648) and everthing was fine. I have no idea how the string got in there.
0 Kudos
Message 6 of 11
(5,129 Views)
On my computer it changes it to a string because it is invalid.  I'm running 8.2, what version are you using?
0 Kudos
Message 7 of 11
(5,126 Views)
I'm running 8.5. I just tried 8.2.1 and I see the same thing as you. It looks like a bug to me too but one that has been fixed.
0 Kudos
Message 8 of 11
(5,124 Views)
A workaround for 8.2 seems to be to change the Case Structure Radix to Hex and type in FFFFFFFF for the U32 max value. That works fine.
Jarrod S.
National Instruments
Message 9 of 11
(5,105 Views)
Edit : Sorry, missed most of the thread... was answering directly the original question, without reading other's posts. Should return to bed... 😞 😄


Message Edité par chilly charly le 11-10-2007 01:49 PM
Chilly Charly    (aka CC)
0 Kudos
Message 10 of 11
(5,089 Views)