It's easy. Imagine 0b1111 1010 is your number. For selecting parts of the byte, you just have to use the "shift" operator. This operation moves the bits in the number left or right. So if I shift 4 bit to the right, the number will looks like this : 0b 0000 1111. In C, you use << for shifting bits to the left, and >> for shifting bits to the right. You have to do x >> y, wher x is your number and y the number of bits you what to shift.
So if you what to select the first part of the number, you do number >> 4.
The the second part (1010 in our case) you have to use a bit mask to 'mask' the first part. For that, you use the & (bit and) like this :
number & 0b0000 1111.
For more info check this :
https://en.wikipedia.org/wiki/Bitwise_operation#AND and
https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shiftTL;DR :
- Code:
left_half = number >> 4;
//if it doesn't works, try left_half = (number >> 4) & 0b 0000 1111;
right_half = number & 0b0000 1111;