I am interested in writing a function getMyByteChunkFunction
that accepts two parameters - a 32-bit integer and a byte offset (0, 1, 2, or 3), then returns the corresponding byte out of the 32-bit integer. For example, given this integer:
(3) (2) (1) (0) ---byte numbers
int word = 10101010 00001001 11001010 00000101
the function call getMeByteChunkFunction(word, 2)
returns 00001001
.
However, I am limited in the bitwise operators I can use. I am only allowed to use >>
, <<
, and exactly one subtraction. I know how to do this using AND and XOR, but I don't know how I'd use a subtraction here. Any ideas?