LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any way to put a boolean array into a case structure without the boolean array to number function?

Solved!
Go to solution

I just figured out, the logical shift and rotate left with carry functions are not compatible with the EV3. 😞 Any other ideas?

 

Is there any way to put a boolean array straight into a case structure?

0 Kudos
Message 11 of 17
(1,676 Views)

Does the Power Of 2 primitive work in the EV3?


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
Message 12 of 17
(1,664 Views)
Solution
Accepted by topic author chasemcd1745

The simplest functions you need for this are Select or case, Add, Multiply and a shift register. You iterate over the array and if the current value is T, you add N to the running total, where N is the current power of 2. If the power of 2 function is available, you can use that on the i terminal. If it's not, you can simply track it yourself with another shift register and multiplying the value in the second SR by 2 in each iteration.

 

This code is a very literal interpretation of how binary numbers are represented.


___________________
Try to take over the world!
Message 13 of 17
(1,650 Views)

@crossrulz wrote:

Does the Power Of 2 primitive work in the EV3?


Yes it does!

0 Kudos
Message 14 of 17
(1,624 Views)

 

tst wrote:

The simplest functions you need for this are Select or case, Add, Multiply and a shift register. You iterate over the array and if the current value is T, you add N to the running total, where N is the current power of 2. If the power of 2 function is available, you can use that on the i terminal. If it's not, you can simply track it yourself with another shift register and multiplying the value in the second SR by 2 in each iteration.

 

This code is a very literal interpretation of how binary numbers are represented.


I understand what you're saying, and it will work, but could you explain a little more, or maybe show an example? 

 

My understanding: I have an array, it goes into a for loop through a shift register, then into a case structure of true or false. If it is T, then it goes into another for loop and is added to a power of 2 function whose x is connected to the i of the outside for loop. There are some errors I know, but can you show me what I'm doing wrong?

0 Kudos
Message 15 of 17
(1,609 Views)

I got it to work finally. Thanks to a combination of your answers! Thanks so much for all your help. (I probably still WAY overcomplicated it).

0 Kudos
Message 16 of 17
(1,590 Views)

@chasemcd1745 wrote:

I probably still WAY overcomplicated it.


Not that part, but the rest of it, yes. I didn't examine the code closely, but there are a number of things which jump out even on a cursory look:

 

  1. The most obvious issue is that you have duplicated code. When you have something like that you should pretty much always think loop or subVI. The point is that you should have one copy of the code and give it the relevant parameters. This makes things easier to write, easier to read, easier to understand and easier to debug.
  2. Cleaning up helps a lot. Straight wires make a straight mind.
  3. You don't need to tell the for loop how many times to run if you're auto-indexing. That operation sets the number of iterations.
  4. If you want N elements out of an array, there's a function for that. You don't need a loop. I'll let you find the function yourself.
  5. For completion, here's the primitive code:
    Binary.png
  6. Note the use of appropriate data types, as well as the fact that this code is basically also a test that it works correctly.

___________________
Try to take over the world!
0 Kudos
Message 17 of 17
(1,574 Views)