LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Change Bit Field

What would be the bitwise operation(s) to change x adjacent bits in a bit field of say 16 bits in labview. The fastest and most memory efficient method would be ideal.
0 Kudos
Message 1 of 9
(3,746 Views)

You would XOR it.

 

Let's say you have 10101010 and you want to change the 2nd, 3rd and 4th bit (counting from left in this example),  XOR it with 01110000.  Now you have 11011010

 

Other bit operations to note,  turning on a bit no matter its current state, OR it with 1  so 01110000 for the same bits.

Turning off a bit no matter its current state And it with 0, so 10001111 for the same bits (other bits must be 1)

Message 2 of 9
(3,744 Views)
ok what if i wanted to change the underlined bits in 0110101010 to any 4 bit arrangement I want. How would I do that?
0 Kudos
Message 3 of 9
(3,742 Views)

Hi Einstein,

 

you would combine 2 methods:

- first you can clear the bits by using AND

- second you can set the bits using OR

As easy as it is...

 

You should also clear what a "bit field" is to you! Do you speak of boolean arrays (use ReplaceArraySubset then) or integer numbers (do as described above)?

Message Edited by GerdW on 04-21-2009 11:30 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 9
(3,733 Views)

You would AND the given bits with 0000 (leaving all other bits 1) to clear them, then OR the result with the pattern you wanted (all other bits 0) to set them.  So, if you wanted to change your underlined bits to 0110, you would do:

(0110101010 AND 1000011111) OR 0011000000 = 0011001010

Message 5 of 9
(3,730 Views)
What would be the most memory efficient implmentation?
0 Kudos
Message 6 of 9
(3,723 Views)
To do what? You have not indicated whether you're dealing with a single 16-bit number or an array of 16 elements (such as an array of Booleans). The "fastest" and "most efficient" method depends on this.
0 Kudos
Message 7 of 9
(3,704 Views)
If I'm modifying bit fields with in a U-16, what would be the most memory efficient way to implement the AND-OR algorithm? I tried converting numbers into boolean arrays but it sucked up resources as i will be doing this asynchronously 100s of times a second.
0 Kudos
Message 8 of 9
(3,701 Views)
The boolean operations accept integer inputs and act on them bitwise, so you can wire your U16s directly into AND and OR.  To see the boolean value you can right-click on a constant or control, make the radix visible, and set the radix to binary.  You may also find the logical shift operation useful, found in the Numeric->Data Manipulation palette.
0 Kudos
Message 9 of 9
(3,673 Views)