2
\$\begingroup\$

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?

\$\endgroup\$
7
  • 2
    \$\begingroup\$ You don't have to convert anything, simply do a shift. The result will be the same. \$\endgroup\$ Commented Sep 9, 2019 at 20:17
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Rob B.
    Commented Sep 9, 2019 at 20:37
  • 4
    \$\begingroup\$ 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) \$\endgroup\$
    – Huisman
    Commented Sep 9, 2019 at 20:45
  • 1
    \$\begingroup\$ Left and right shifting in binary are equivalent to dividing and multiplying by 2, if that helps? \$\endgroup\$ Commented Sep 9, 2019 at 20:49
  • \$\begingroup\$ It's easy if the shift amount is a multiple of 4. \$\endgroup\$
    – Justin
    Commented Sep 9, 2019 at 21:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.