If I understand correctly, you have a
Byte
and want to modify the third bit counting from the left.
This is possible, but you have to know which operation you want to do on the third bit. I can come up with three options: 1) You want to set the bit to
1
. 2) You want to set the bit to
0
. 3) You want to flip the bit (0 becomes 1 and 1 becomes 0).
If you want to do the first operation (setting the bit to 1), you can do this:
Dim modifier As Byte = 32
Dim result As Byte = arr(3) Or modifier
This performs the bitwise OR operation.
If you want to do the second operation (setting the bit to 0), you can do this:
Dim mask As Byte = 223
Dim result As Byte = arr(3) And mask
This performs the bitwise AND operation.
If you want to do the third operation (flipping the bit), you can do this:
Dim modifier As Byte = 32
Dim result As Byte = arr(3) Xor modifier
This performs the bitwise XOR operation.
To learn more about these bitwise operations, refer to my article:
Understand how bitwise operators work (C# and VB.NET examples)[
^]