LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using type cast to cast a hexidecimal string (byte) into a boolean.

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 😛

 

 

Best Regards,

Øyvind

CLAD
32 bit LV2015
64 bit Windows10
0 Kudos
Message 1 of 6
(3,444 Views)

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

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 2 of 6
(3,433 Views)

 


@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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 6
(3,432 Views)

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

0 Kudos
Message 4 of 6
(3,410 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 6
(3,393 Views)

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 🙂

 

 

Best Regards,

Øyvind

CLAD
32 bit LV2015
64 bit Windows10
0 Kudos
Message 6 of 6
(3,361 Views)