LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Control bits and join number

Solved!
Go to solution

Hi,

 

I need to control each bit of a 16 byte integer to control different functions and I dont know how to do it, I need to control the bits 0 to 3 and 7 of the table.

ADaniel01_0-1666161616624.png

ADaniel01_1-1666161646650.png

 

 

0 Kudos
Message 1 of 14
(2,424 Views)

Hi A.,

 


@A.Daniel01 wrote:

I need to control each bit of a 16 byte integer to control different functions and I dont know how to do it, I need to control the bits 0 to 3 and 7 of the table.


First: do you need to handle a "16 byte integer" entity or a standard U16 value (containing 16 bits)?

 

Then: when you need to handle an U16 then why do you use I8 and U32 controls in your image? Why use 3 Join functions???

 

See this:

It only takes an OR to set (and an AND with a negated mask to clear) a bit in an U16…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 14
(2,416 Views)

I use 3 join functions because the final result is a U64, the controls are other functions. I only need to know how to control true or false each byte of a U16 with something like a bool array.

0 Kudos
Message 3 of 14
(2,398 Views)

Hi A.,

 


@A.Daniel01 wrote:

I only need to know how to control true or false each byte of a U16 with something like a bool array.


Again you write "byte" when you actually mean "bit"!

 

You might use an array of 16 booleans and convert it to an U16 number in the end. Or you follow my suggestion to use AND/OR/XOR directly on your U16 value as shown above: no need to convert to/from boolean array…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 14
(2,390 Views)
Solution
Accepted by topic author A.Daniel01

@A.Daniel01 wrote:

I use 3 join functions because the final result is a U64, the controls are other functions. I only need to know how to control true or false each byte of a U16 with something like a bool array.


The easiest way is Number to Boolean array, Index array/Replace array and Boolean array to number. They're in the Numeric -> conversion- and Array-palettes respectively.

The best way is with ORs and ANDs

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 14
(2,330 Views)

@Yamaeda wrote:

@A.Daniel01 wrote:

I use 3 join functions because the final result is a U64, the controls are other functions. I only need to know how to control true or false each byte of a U16 with something like a bool array.


The easiest way is ....

The best way is with ORs and ANDs


I would say ORs & ANDs are the easiest and best way.

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
Message 6 of 14
(2,298 Views)

@Frozen wrote:

@Yamaeda wrote:

@A.Daniel01 wrote:

I use 3 join functions because the final result is a U64, the controls are other functions. I only need to know how to control true or false each byte of a U16 with something like a bool array.


The easiest way is ....

The best way is with ORs and ANDs


I would say ORs & ANDs are the easiest and best way.


Not if you're bit-wise operation challenged like me!  I think that, self-documentation-wise, breaking out the bits and substituting as needed is better because you are literally doing what is being called for.  At the expense of optimization, of course, but it's (almost) always a choice between code clarity and code optimization.  It just depends on where you want to draw the line.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 14
(2,291 Views)

@A.Daniel01 wrote:

Hi,

 

I need to control each bit of a 16 byte integer to control different functions and I dont know how to do it, I need to control the bits 0 to 3 and 7 of the table.

ADaniel01_0-1666161616624.png

ADaniel01_1-1666161646650.png

 

 


This is called Bit Masking or simply a Bitmask,  here's the Wikipedia 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 14
(2,273 Views)

If you want to create a U8 (or U16, or U32) with one bit (where the least significant bit is bit 0) set, you can use the function that I "overlooked" until I needed to do exactly what you're trying to do, set/clear bits in a 16-bit "Binary Register", namely "Scale by Power of 2", where the bit number is the "power of 2" and the value you are scaling is the U8 (or U16 or U32) value 1.  You can use this to set a bit by OR-ing it with the current value.  If you need to clear the bit, simply Negate this "power of 2" and AND it with the current value, thereby keeping all of the bits you are not trying to clear.

 

It's harder to say than to write the code, but if you do write the code, you'll (a) learn how this works, (b) will be able to test the code you've written and verify that it works as you expected.  If you have an "off-by-one" error, put additional indicators (or Probes) on your wires and figure out for yourself what went wrong.

 

Bob Schor

0 Kudos
Message 9 of 14
(2,263 Views)
Solution
Accepted by topic author A.Daniel01

I just did this:

ADaniel01_1-1666251078178.png

 

 

Message 10 of 14
(2,213 Views)