LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
Pieter_B

Number to Boolean array Enhancement

Status: Declined

Declined for reasons listed in idea discussion thread.

When an integer is converted to a Boolean array, this size of the Boolean array depends on the type of integer that is wires to the input, which is 8 for an I8 and 16 for an I16. In case the number 3 needs to be converted and is stored in an I8, the result is 00000011, while only 11 is relevant. Of course it is possible to program this functionality self but if there is a simple configuration where you can select this behavior this would make life easier.Number to Boolean array Enhancement1.png

11 Comments
crossrulz
Knight of NI

But what if you wire up a 1.  It won't be of the same length as your 3.  If doing weird bit manipulations (ie flags), that will be a HUGE issue.  I just think you will introduce more problems than fix.

 

If you are going to make changes to this function, I would make it an integer input to state the Boolean length.  Of course, you can do that now already by using an Array Subset.  You could put both functions into a Malleable VI and have what you want.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
AristosQueue (NI)
NI Employee (retired)

"this would make life easier."

 

Can you go into more details about what situations this would make easier? Why are you needing to strip off the leading FALSE values? For every use case I've ever seen, keeping the bits fixed regardless of the value was very important (translating a number to a flickering LED panel being the most common).

wiebe@CARYA
Knight of NI

I'd say that if this is useful to you, it's because of a specific project you're working on. That happens. I don't think I've ever needed exactly this.

 

I agree with the others that the variable length, depending on the number would be very error prone and at least not very practical.

 

If the input was a number, I'd see some usefulness. So you'd wire a 4, and the output would always be a 4 element array. Then again, we can make that our self with a .vim. But the main reason for me to want this is to limit memory allocation. A .vim will provide the functionality, but wouldn't solve that. I doubt that evaluating the number bit by bit for the number of elements would beat a Number to Boolean Array followed by a Reshape Array...

 

Of course a .vim will also allow the exact solution you're suggesting, without the efficiency of a native function.

Pieter_B
Member

@crossrulez:

If I wire a 1 then the binary array would be only 1 element long.

Other examples

3 --> 11 --> 2 elements long

6--> 110 --> 3 elements long

13 --> 1101 --> 4 elements long

100 --> 1100100 --> 7 elements long

I don't see why this would introduce weird bit manipulations, it's just cutting off the irrelevant bits. 

 

 

Pieter_B
Member

It's also my experience most of the time a number conversion to a 8, 16 or 32 bit Boolean array will work. But I can give an example where this will not work.

 

We have here (specific) equipment that generates 230 V sine waves based on a bit pattern and length that is send to it, where each bit stands for a half sine. By varying the bit pattern and the length it is possible to dose electric power in a very controlled way without having too much troubles with Flicker requirements.

 

The power dosage is then the result of (amount of active half sine wave in a patter / pattern length).

 

If the length would be fixed to 8, 16 or 32 then this would strongly limit the possible power dosage steps.

 

@Wiebe: Can you show me a solution with a .vim?

wiebe@CARYA
Knight of NI

>@Wiebe: Can you show me a solution with a .vim?

 

Sure. Except attachments are not allowed... The code would be pretty simple:

Number to Smallest Boolean Array.png

I think it would be better to make the function without the enum, so there are two dedicated functions: Number to Boolean Array and Number to Smallest Boolean Array, but that's up to you.

 

EDIT: Hold on this solution has a rounding error when using U64's...

wiebe@CARYA
Knight of NI

>@Wiebe: Can you show me a solution with a .vim?

Number to Smallest Boolean Array.png

Ah well, not as clean as I'd hoped for, but should work pretty well. Of course the extra check only needs to be done for the 64 bit numbers. So adding a type check would make it slightly more efficient. Haven't tested all numbers Smiley Very Happy.

 

There might be more efficient ways, but I tried to avoid looping. Looping might be more efficient though, especially for small numbers:

Number to Smallest Boolean Array 2.png

AristosQueue (NI)
NI Employee (retired)

Another looping solution. For comparison.

snip.png

AristosQueue (NI)
NI Employee (retired)

Peter_B, I read your use case. That's an unusual system, in my limited experience. I hope the subVIs Weibe provided help.

Pieter_B
Member

I also found a solution myself but the one provided by Wiebe is way more elegant Smiley Happy  so I'll use that one. If this my case is really to specific I can imagine to leave the current situation in place.