11-29-2010 03:30 AM
Hi,
I have a remark regarding type casting, in case anyone are having the same situation. I have a hexidecimal sting (not ascii) of 1 byte and want to type cast it to a boolean value. Sounds pretty straight forward, one should think that for the value of 00 it would be False and for all other values it would be True. This is also the case. What puzzles me is that if the hexadecimal string is FF and type casting it to boolean the byte information is still in the boolean. So when I type cast it back to a hexadecimal string it still contains the same value it had before. If the boolean is set to false and then to true, the value is "reset" to 01.
So (-> means type cast)
FF -> True -> FF
01 -> True -> 01
00 -> False -> 00
A boolean in labview is not a boolean 😛
11-29-2010 04:15 AM
Hi Blueprint,
Yes, it is known in LabVIEW that a single boolean variable is stored in a whole byte of memory space, not a single bit, and thus can contain a full byte of information. Therefore, your 0x01 and 0xFF values are preserved and can be recovered when typecasting back to strings.
Thoric
11-29-2010 04:17 AM
@Blueprint wrote:
[...]A boolean in labview is not a boolean 😛
Well, no programming language has a boolean as a bit nowadays.
Therefore, the LV boolean is exactly a boolean. Therefore, why should LV alter the value of the bits with typecast when boolean defines value == 0 => False, value != 0 => True.....
Norbert
11-29-2010 07:42 AM
Type casting changes the interpretation of the data but does not change the data itself (unless cast to a datatype with a different length). If you want to change the data, you will need to do something other than type casting. If you want the boolean to string to do something different, please define what you want it to do.
Lynn
11-29-2010 09:35 AM
As i understand the boolean, it is due to cross-platform purposes.
Not all CPU's have "BBS" (branch if bit set) but a compare with zero is common.
Ben
11-30-2010 05:48 AM
Thanks for the inputs to this discussion:)
In my program, I have to treat 0x01 as true and all other values as false due to interfacing HW, so I just made a VI for it. As suggested, it seems that it is common to use True for all non-zero values of a boolean for most languages.
Guess I learned something 🙂