10-27-2009 09:22 AM
Sticking with the efficiency theme, this one has me (and a few others) scratching their heads, "Boolean to (0,1)". Seems pretty straightforward, boolean in and either a 0 or 1 out. What is interesting is the choice of I16 for the representation of 0 or 1. It isn't so much that you are now using 16-bits to hold 1 bit of information, but how often do you use the I16 data type? If you are indexing an array or loop you are using I32 (or coercing), if you are working with byte arrays you use U8. Which now makes me think, why the heck do you use a signed representation for 0/1?
My guess is that in the old days booleans were stored in two bytes (it must have seemed like a good idea at the time), and this is a remnant. What we are left with is a potentially useful function that we have to either follow with a conversion, replace with Select or Type Cast or live with a coercion.
I believe there is a movement afoot in the idea exchange to get this changed.
VIOTD groundrules here.
10-27-2009 09:29 AM
10-27-2009 09:33 AM
10-27-2009 09:39 AM
10-27-2009 09:41 AM
smercurio_fc wrote:
Actually, Booleans are stored as 8-bit values. It used to be that they were stored as 1-bit values. But that was a loooooong time ago. This little tidbit is what makes this little trick possible.
Booleans are now one byte in or out of arrays. Used to be they were 2 bytes outside of an array and 1-bit inside of an array. The 1-bit representation is still very useful, especially when dealing with image masks. The one byte representation is very useful for code obfuscation, if nothing else. Is there anything else?
10-27-2009 09:54 AM
I use this guy when reading an error cluster or other boolean to a 3-way LED. Not sure if this is the best approach, but ?1:0 saves me a Select and some wiring. The 3way LED is a 3 item pict ring with images for off, green, and red.
(LV2009f2)
10-27-2009 09:55 AM
Darin.K wrote:
Booleans are now one byte in or out of arrays. Used to be they were 2 bytes outside of an array and 1-bit inside of an array.
Ah-hah! That was it. I knew there was a 1-bit storage of something in the dark, dreaded past. Your memory is clearly better than mine.
10-28-2009 08:19 AM
smercurio_fc wrote:
This little tidbit is what makes this little trick possible.
I can't figure out how that works. It actually seems pretty scary that others were able to do the same thing, but with other strings coming out. Can anyone explain that to me?
10-28-2009 08:25 AM
10-28-2009 08:33 AM
Darin.K wrote:Sticking with the efficiency theme, this one has me (and a few others) scratching their heads, "Boolean to (0,1)". Seems pretty straightforward, boolean in and either a 0 or 1 out. What is interesting is the choice of I16 for the representation of 0 or 1. It isn't so much that you are now using 16-bits to hold 1 bit of information, but how often do you use the I16 data type? If you are indexing an array or loop you are using I32 (or coercing), if you are working with byte arrays you use U8. Which now makes me think, why the heck do you use a signed representation for 0/1?
![]()
My guess is that in the old days booleans were stored in two bytes (it must have seemed like a good idea at the time), and this is a remnant. What we are left with is a potentially useful function that we have to either follow with a conversion, replace with Select or Type Cast or live with a coercion.
I believe there is a movement afoot in the idea exchange to get this changed.
VIOTD groundrules here.
The real reason can only be provided by someone who was in the meeting can tell us for sure but I'll speculate...
Since LV is cross-platform capable, ther various branching operations supported by the mulitude of patforms LV was targeted at was taken into concideration. A common machine operation is to "branch if negative". By writing all bits as true or false when a branch if negative is executed the MSB of the I16 is set making it negative.
So I suspect the "lowest common denomenator" across platforms was a branch if negative.
Rolf (if he is listening) is much more familair with the platform abstraction layer than I so maybe he could shed more than speculative light on this Q.
Ben