04-21-2009 04:07 PM
04-21-2009 04:12 PM
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)
04-21-2009 04:17 PM
04-21-2009 04:28 PM - edited 04-21-2009 04:30 PM
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)?
04-21-2009 04:29 PM
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
04-21-2009 05:10 PM
04-21-2009 05:44 PM
04-21-2009 06:02 PM
04-22-2009 07:35 AM