0

I'm currently storing a byte inside an unsigned integer (0010 1100). How do I get rid of the 2 most significant bits in that sequence to leave a 6 bit number: 10 1100?

lurker
  • 56,987
  • 9
  • 69
  • 103
Andy
  • 3
  • 1
  • What do you mean "get rid of"? Do you mean when you display the value? You can't get rid of the bits inside the machine, I'm afraid. – lurker Dec 15 '17 at 00:13
  • If you are trying to pack multiple 6 bit values, you have to shift and apply `|`. You need 96 bits to fully pack 16 of your 6 bit values into 12 octets. If non-word boundaries are okay, you can use 3 octets to encode 4 of you 6 bit values. – jxh Dec 15 '17 at 00:15
  • Because basically I have a 8 bit number, The 2 most significant bits are the opcode, the last 6 are the operand. When I extract the operand I am left with the last 6 bits but since it is stored in a byte, the first 2 most significant bits are 0. This leads to problems when I try and turn the operand into a signed number – Andy Dec 15 '17 at 00:23
  • You did not describe your actual problem in your question, and thus your question was closed. Your actual problem in your comment is much more interesting than what you shared in your post. Please consider modifying this question, or posting a new question with your actual problem, rather than the problem you assume will help you solve your problem. See https://meta.stackexchange.com/q/66377/228525m – jxh Dec 15 '17 at 00:29
  • "This leads to problems" - what problems? It is not clear to me what you are asking. Do you actually want to work with 6-bit signed integers? – M.M Dec 15 '17 at 01:00

0 Answers0