Questions about this topic? Sign up to ask in the talk tab.

Bitwise math/Logical shifts

From NetSec
Jump to: navigation, search
back to Bitwise math


For logical shifts, the bytes are assumed to be in big endian.

Using A or 1010 as an example:

Example: A shifted left by 1 = 4
Operation Hexadecimal Binary comment


Left Shift

A

1

1010

0001

shifted to the left once, the 1 at the beginning gets shifted off, thus the binary value becomes 0100, or 4 in hexadecimal.
= 4 0100 The end value 0 is always used to replace the residual numbers.


Example: A shifted left by 2 = 8
Operation Hexadecimal Binary comment


Left Shift

A

2

1010

0001

The first `10' is shifted off and the remaining two placeholders get zeroed out.
= 8 1000 The end value 0 is always used to replace the residual numbers.




Example: A shifted right by 1 = 5
Operation Hexadecimal Binary comment


Right Shift

A

1

1010

0101

a single shift to the right is division by two for even numbers.
= 5 0101 The end value 0 is always used to replace the residual numbers.


If 'A' is shifted to the right twice it goes from 1010 to 0010

Operation Hexadecimal Binary comment


Right Shift

A

2

1010

0001

shifted to the right twice, the one at the beginning gets shifted to the 2nd digit and the one in the 2nd digit place gets shifted off, thus the binary value becomes 0010, or 2 in hexadecimal.
= 2 0010 The end value 0 is always used to replace the residual numbers.

At this point, understanding should be emerging into real hacking and cryptography. If understanding is not attained regarding this knowledge, further extension topics will prove difficult. Thus, it is considered a baseline knowledge.