2

In binary, bitshifting is pretty straight forward for example, a binary number of:

10000001

with a left bit shift of 1 becomes :

00000010

However in Hex, a hex number of:

1051

with a left bitshift of 1 becomes:

20a2

Is there an intuitive way to calculate bitshift in hexdecimal, or is it simply easiest to convert from hex to binary, apply the bitshift, and convert from binary back in to hex decimal?

  • 2
    You don't have to convert anything, simply do a shift. The result will be the same. – Marko Buršič Sep 09 '19 at 20:17
  • 1
    You asked for an intuitive way, but really it's a matter of practice and learning to think in hex. When you work with it as an engineer you use it so much that it becomes easier. – Rob B. Sep 09 '19 at 20:37
  • 4
    Just multiply or divide by two in hexadecimal or octal sytem the way you perform it for decimal numbers (long multiplication by 2 is not that hard by heart) – Huisman Sep 09 '19 at 20:45
  • 1
    Left and right shifting in binary are equivalent to dividing and multiplying by 2, if that helps? – Harry Beadle Sep 09 '19 at 20:49
  • It's easy if the shift amount is a multiple of 4. – Justin Sep 09 '19 at 21:00
  • Bit shifting in hex would be like adding or subtracting \$16^n\$, where \$n\$ is the place of where the digit lies... but I like @Huisman 's explanation. –  Sep 09 '19 at 21:59
  • @HarryBeadle Not necessarily, and not without qualifications. Right shifting must be handled differently for signed and unsigned values, and left shifting too far completely corrupts the data. – Elliot Alderson Sep 09 '19 at 22:12

0 Answers0