Sitemap

Shift Micro Operations

3 min readMar 3, 2025

--

Press enter or click to view image in full size

Shift micro-operations are fundamental bitwise operations used in computer architecture to move data bits left or right within a register. These operations are useful for data manipulation, arithmetic operations, and logical decisions in CPUs.

logical shift

A logical shift is a bitwise operation that moves bits to the left or right while filling the emptied positions with zeros. It is commonly used in low-level programming, such as bit manipulation, cryptography, and performance optimizations.

Logical Right Shift

  • Shifts bits to the right.
  • Fills the leftmost bits with zeros.
  • Equivalent to integer division by powers of 2 (for unsigned numbers).
Press enter or click to view image in full size
00011010  (26 in decimal)
>> 2
00000110 (6 in decimal)

Logical Left Shift

  • Shifts bits to the left.
  • Fills the rightmost bits with zeros.
  • Equivalent to multiplying by powers of 2.
Press enter or click to view image in full size
00011010  (26 in decimal)
<< 2
01101000 (104 in decimal)

Arithmetic shift

An arithmetic shift is a bitwise operation similar to a logical shift, but it preserves the sign of signed integers (in two’s complement representation). This is particularly important when dealing with negative numbers.

Get Yahia zakaria’s stories in your inbox

Join Medium for free to get updates from this writer.

Arithmetic Left Shift

  • Works the same as a logical left shift.
  • Bits are shifted left, and zeros are filled on the right.
  • Effectively multiplies by powers of 2.
Press enter or click to view image in full size
00011010  (26 in decimal)
<< 2
01101000 (104 in decimal)

Arithmetic Right Shift

  • Shifts bits to the right.
  • Preserves the sign by filling the leftmost bits with the sign bit (0 for positive, 1 for negative numbers).
  • Effectively divides by powers of 2 while rounding toward negative infinity.
00011010  (26 in decimal)
>> 2
00000110 (6 in decimal) # Positive number, behaves like logical shift

Circular Shift

A circular shift, also known as a rotate operation, moves bits to the left or right without discarding them. Instead of filling empty positions with zeros (like logical or arithmetic shifts), the bits that fall off are wrapped around to the other end.

Circular Left Shift (Rotate Left, ROL)

  • Bits shift to the left.
  • The leftmost bit moves to the rightmost position.
Press enter or click to view image in full size
10110011  (179 in decimal)
Circular Left Shift by 2:
11001110 (206 in decimal)

Circular Right Shift (Rotate Right, ROR)

  • Bits shift to the right.
  • The rightmost bit moves to the leftmost position.
Press enter or click to view image in full size
10110011  (179 in decimal)
Circular Right Shift by 2:
11101100 (236 in decimal)

--

--

Yahia zakaria
Yahia zakaria

Written by Yahia zakaria

Thoughts, notes, and new things I've learned.