LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (10/27/2009) - Boolean to (0,1)

Not sure if this was ever a factor when that decision was made, but in C Booleans are commonly represented by (signed) integers, and a value of 0 was considered to be False, while any non-zero value was considered to be True. In fact, it was quite common to see something like this:

 

#define FALSE (0)

#define TRUE (-1)

typedef int bool;

 

Furthermore, the size of "int" has not always been the same, as we've gone from 8-bit processors to 32 and 64-bit processors. So, at one point, "int" was really just 16-bits. Nowadays we affectionately know it as a "short int". How long will it be, I wonder, when the 32-bit integer is known as "short int", and the 16-bit integer is known as "stunted int"? 

Message 11 of 19
(1,362 Views)
Along those lines, a couple of things I had to ween myself from in going from C to LV were side-effects and short-circuits.  Useful constructs in C where you have a simple intermingling of booleans and numbers.  In LV with booleans sequestered to their own type, I have never fully understood the logic behind their representation.  (Except for the time when they were 1-bit in an array, that makes sense).
0 Kudos
Message 12 of 19
(1,354 Views)

You don't like I16, make your own Boolean to 0,1:

 

U8 Boolean convert.png

0 Kudos
Message 13 of 19
(1,348 Views)

Hi Nickerbocker,

 

why not extend your example to a new LV idea:

make the output datatype of "boolean to 0/1" configurale as you can do for other functions (like "add"...). Atleast any integer type should be allowed!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 14 of 19
(1,343 Views)

GerdW wrote:

Hi Nickerbocker,

 

why not extend your example to a new LV idea:

make the output datatype of "boolean to 0/1" configurale as you can do for other functions (like "add"...). Atleast any integer type should be allowed!


As Ben noted, there's an existing idea for that.  Let's all go Kudo it! Smiley Very Happy
Message 15 of 19
(1,335 Views)

Darin.K wrote:
Along those lines, a couple of things I had to ween myself from in going from C to LV were side-effects and short-circuits.  Useful constructs in C where you have a simple intermingling of booleans and numbers.  In LV with booleans sequestered to their own type, I have never fully understood the logic behind their representation.  (Except for the time when they were 1-bit in an array, that makes sense).

 

The KL-10

 

 

 

 

 instruction set was the most powerful set I ever worked with. it was developed by a bunch of EE that understood computers but did not program them. Included in that instruction set were machine level operations that let you compute complex surfaces like a sadle (hyperpola up combined with another down). A whole section of the command set included support for varible bit field lengths so we could work with 3-bit nibbles if we wanted.

 

After an adventure through the VAX-11

 

 

 

instruction set ( included commands like Insert at head of queue interlocked to support multi-CPUs sharing memory) the wolrd responded with RISC (reduced instruction set computers) that settled on a minimal set of instruction that could be combined to realized those crazy instruction found in the robust architectures.

 

So...

 

Single bit representations were just too fancy AND the CPU had to work in "register-sized" chuncks anyway so why bother with including logic for single bit operations.

 

Just my 2 cents,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 16 of 19
(1,333 Views)

Ben wrote:

 

Single bit representations were just too fancy AND the CPU had to work in "register-sized" chuncks anyway so why bother with including logic for single bit operations.

 

Just my 2 cents,

 

Ben


So, you're saying that a bit is like a penny? We're going to need have a "Need a bit, give a bit" little container next to computers... Smiley Very Happy

Message 17 of 19
(1,322 Views)
GerdW - Yup, I'll kuddo. that.
0 Kudos
Message 18 of 19
(1,304 Views)

GerdW wrote:

Hi Randy,

 

two facts:

1) a boolean is (nowadays) stored as 8bit entity internally

2) any value different than zero is TRUE

 

Do you need more hints?


 

 

Still stumped. I get that this is somehow a memory thing, because I deleted a bunch of the bools in JP's array and then added them back in and just got x01 for each one I put back in. But I don't understand... Oh wait. I get it now! Funny how typing things out can make it make sense. Smiley Happy I hadn't thought about looking at it from that angle (obviously)... Thanks!

Message Edited by RandyP on 10-29-2009 11:09 AM
-Randy
-=--=-=-=-=-=-=-
Nothing like a good dose of LabVIEW to cure what ails ya'.
0 Kudos
Message 19 of 19
(1,236 Views)