+ 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?

21st Oct 2019, 11:47 AM
David Wood
David Wood - avatar
1 Réponse
+ 2
You could use a 12-bit bitfield and to variables of unsigned char type: https://code.sololearn.com/c20m98gQHQeM/?ref=app
21st Oct 2019, 3:16 PM
Michael
Michael - avatar