0

Let's say for example that I have this 16-bit binary 0b1010001110011011 and i want to shift it by 6 bits to the left so the result is 0b1110011011101000. When i tried print(bin(example << 6)) the result is 0b1010001110011011000000

  • Where should the bits go? Do you want to widen the datatype and now have 22 bytes (16+6)? – luk2302 Nov 02 '21 at 09:08
  • 2
    This is called a rotation, not a shift. You can adapt form https://www.geeksforgeeks.org/rotate-bits-of-an-integer/ –  Nov 02 '21 at 09:09
  • "When i tried print(bin(example << 6)) the result is 0b1010001110011011000000" Okay, and why is that result wrong? Looks to me like it has all the bits from the original, `1010001110011011`, shifted to the left by `6`, leaving `000000` at the end. That's exactly what "shift it by 6 bits to the left" means. It seems like you wanted to put the high-order 6 bits into the low order places while shifting the *other* bits. As noted, that's called *rotation*, not shifting. – Karl Knechtel Nov 02 '21 at 09:11

0 Answers0