LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

why is my 1 type cast to value 0 enum?

I've attached a VI that (for me, on my XP machine) typecasts my integer with value 1 to an enum with value 0.  I'm certain I've done this type of thing before with (what I believe) is the correct answer of the enum with value 1.

Am I crazy to expect a different result?

   ...Dan
0 Kudos
Message 1 of 6
(3,360 Views)
Change your numeric's datatype to U16 (or I16).

Message Edited by smercurio_fc on 04-30-2007 12:06 PM

Message 2 of 6
(3,356 Views)

You can also change the type of the enum diagram constant to U32.

Still, I agree with you that it should work as you expect and not as it currently does. A One is a One is a One... after all.

It should not depend on the representation of the players. Am I missing something?

Message 3 of 6
(3,338 Views)
It does, once you read the details on the Type Cast function:

This function can generate unexpected data if x and type are not the same size. If x is of a larger data type than type, this function uses the upper bytes of x and discards the remaining lower bytes. If x is of a smaller data type than type, this function moves the data in x to the upper bytes of type and fills the remaining bytes with zeros. For example, a U8 with value 1 type cast to a U16 will result in a value of 256.

So, in the case of the input being an I32 and the enum being a U16, the Type Cast is convert the upper bytes of the I32, which are all zero.
Message 4 of 6
(3,333 Views)
Thanks to all -- you guys are sharp.

I did figure that out shortly after posting the question -- that must be one of Murphy's unpublished laws, "the answer will come to you immediately after posting for help".  Anyway, it's fair to say that a typecast is not a type conversion.

   ...Dan
0 Kudos
Message 5 of 6
(3,324 Views)
The OpenG library has a function that handles this sort of situation. Also, if you happen to have the State Diagram Toolkit there's a neat little function in there for doing this sort of thing, as discussed in this thread.
0 Kudos
Message 6 of 6
(3,319 Views)