10-19-2022 01:43 AM
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.
Solved! Go to Solution.
10-19-2022 01:55 AM - edited 10-19-2022 01:56 AM
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…
10-19-2022 02:28 AM
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.
10-19-2022 02:34 AM
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…
10-19-2022 08:05 AM
@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
10-19-2022 09:22 AM
@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.
10-19-2022 09:36 AM
@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.
10-19-2022 09:49 AM
@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.
This is called Bit Masking or simply a Bitmask, here's the Wikipedia
10-19-2022 10:31 AM
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
10-20-2022 02:31 AM
I just did this: