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

Bitwise math/Bit Rotation

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


Circular shifts, or bit rotation occurs in processors which involves rotate /with carry/. Circular shifts are the same as rotate /without/ carry. So, continuing the usage of a nibble and A (1010) as the example...

If 6 is rotated to the left by 1 it becomes 0101 or 5


Operation Hexadecimal Binary comment


Left Rotate

6

1

1010

0001

shifted to the left once, the 1 at the beginning gets shifted to the first digit, thus the binary value becomes 0101, or 5 in hexadecimal.
= 5 0101 The highest value "loops" back around to the lowest, like a clock/modular arithmetic.

Instead of replacing a value with zero, like a normal shift, the value is taken and shifted off of one side and applied to the other side. So for 1100 (C)

Example: C rotated left by 1, becomes 9 (1001)'
Operation Hexadecimal Binary comment


Left Rotate

C

1

1100

0001

shifted to the left once, the 1 at the beginning gets shifted to the first digit, thus the binary value becomes 1001, or 9 in hexadecimal.
= 9 1001 The highest value "loops" back around to the lowest, like a clock/modular arithmetic.
Example: C rotated right by 1, becomes 6 (0110)'
Operation Hexadecimal Binary comment


Right Rotate

C

1

1100

0001

shifted to the right once, the 1 at the beginning gets shifted to the third digit, thus the binary value becomes 0110, or 6 in hexadecimal.
= 6 0110 Something a little more intuitive

Based upon these examples, a circular shift is not the same thing as a logical shift. Proceeding further, two's complement and something small about binary will be explained.

Remember in the previous lesson, a nibble (four bits) can hold 16 values (the uppermost being 15 because one of these values is 0). Four bits maximum value also = 2^4 - 1. 4 is taken from the number of bits and the -1 from the zero placeholder. If a full byte was going to be shifted, it would be 2^8 - 1. The maximum value of which is 255.