I need an efficient method with the following signature:
public byte SetBits(byte oldValue, byte newValue, int startBit, int bitCount)
Which returns oldValue
, only that starting from its startbit
bit up to its startbit + bitcount
bit (zero-based), it's replaced with the first bitcount
bits of newValue
For example, if:
oldValue = 11101101
newValue = 10000011
startBit = 1
bitCount = 2
Then the result would be: 11101111
(the segment 10
in oldValue
is replaced with the corresponding 11
segment in newValue
)