+ 1
Split 12 bit binary variable into two 8 bits
What would be the best way to split a 12-bit integer into a 4-bit (MSB) integer (that's assigned to an 8-bit variable) and the remaining 8 bits into another 8-bit (LSB) integer? I thought bit shifting would be good, but it preserves the original length of the integer (12), and I want the two new integers to be of length 8. How do I do that?
1 Antwort
+ 2
You could use a 12-bit bitfield and to variables of unsigned char type:
https://code.sololearn.com/c20m98gQHQeM/?ref=app