LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert Boolean to UINT8?

I'm working on an application that stuffs a large number of switch values into bytes to be sent over the serial port.  So I want to use some toggle switches and basically multiply the boolean value by the bit location (*1, 2, 4, 8 for example) to get that bit's value, then sum them up for that byte's final value.
My problem is that I can't seem to get the boolean switch values to typecast to uint8 so that I can do the multiplication.  I'm trying ot use the Type Cast block, but all it seems to do is convert things to strings.  I've tried different things for the "type" input, but the help file on this isn't very useful either.  It doesn't tell me WHAT the valid inputs for this are.  I've tried "UINT8" and "UINT" and "05" since all I can find in the help document is some hex representation of the possible type values. 
I'm rather new to Labview so this is frustrating since I could get it done in C rather easily.  Thanks for any help.
0 Kudos
Message 1 of 6
(10,278 Views)
You should just have to connect a U8 constant to the Type input of the Type Cast function. It will then output a UNIT8 in either a 1 or 0.

There's also function in the Boolean palette named "Boolean to (0,1)". This will convert a boolean to a INT16 by default, but you can insert a conversion to bump it down to a UNIT8 to get the same results.



Ed

Message Edited by Ed Dickens on 11-21-2005 12:41 PM



Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 2 of 6
(10,267 Views)
Use the Boolean to (0,1) function in the palette Numeric >> Conversion >> ... This produces a variable of type I16 so you will need an additional conversion to U8 from the same palette.

Lynn
0 Kudos
Message 3 of 6
(10,260 Views)
Along with Eds comments, if you would need to convert a whole series to a single U8 then you could use the boolian array to number VI (of course you will then need to make the array first).  It might save you some trouble down the line so you wont have to do the conversions yourself...
 
 
Message 4 of 6
(10,256 Views)
Hah! Finally found a "Boolean to 0,1" conversion in the Conversion pallete. I do like the boolean array method though, much fewer blocks.  Thanks!

Message Edited by Plocmstart on 11-21-2005 12:49 PM

0 Kudos
Message 5 of 6
(10,255 Views)

Instead of doing all that math, let Labview do it for you.  Use the Boolean Array To Number function found in Boolean palette.

 

Message Edited by tbob on 11-21-2005 11:57 AM

- tbob

Inventor of the WORM Global
Message 6 of 6
(10,248 Views)