Shift micro-operations move bits left or right within a register and are used in tasks like data storage, serial transmission, multiplication, division, and logical operations. They are often combined with arithmetic and logic operations for efficient processing.
Logical Shift
A logical shift micro-operation involves moving the bits of data in a register either to the left or right, with zeroes being introduced into the empty positions. This operation is used primarily in binary arithmetic and data processing tasks.
There are two main types of logical shift micro-operations:
1. Logical Left Shift
In this shift, each bit is moved to the left by one position. The Empty least significant bit (LSB) is filled with zero (i.e. the serial input), and the most significant bit (MSB) is rejected or discarded. The left shift operator is denoted by the double left arrow key (<<).
The general syntax for the left shift is
"shift-expression" << k
Note: For unsigned numbers, every time we shift a number towards the left by 1 bit it multiplies that number by 2.
Logical Left ShiftUsage: Used in multiplication of unsigned binary numbers.
Example: Let's take an 8-bit unsigned binary number 01010011 (which is 83 in decimal). If we perform a logical shift left:
- Before Shift: 01010011 (83 in decimal)
- After Logical Shift Left: 10100110 (166 in decimal)
2. Logical Right Shift
In this shift, each bit moves to the right one by one. The least significant bit(LSB) is discarded and empty MSB is filled with zero. The right shift operator is denoted by the double right arrow key (>>).
The general syntax for the right shift is
“shift-expression" >> k
Note: For unsigned numbers, every time we shift a number towards the right by 1 bit it divides that number by 2.
Logical Right ShiftUsage: Used in division of unsigned binary numbers.
Example: Let's take the same 8-bit binary number 01010011 (83 in decimal). If we perform a logical shift right:
- Before Shift: 01010011 (83 in decimal)
- After Logical Shift Right: 00101001 (41 in decimal)
Arithmetic Shift
The arithmetic shift micro-operation moves the signed binary number either to the left or to the right position. Following are the two ways to perform the arithmetic shift:
1. Arithmetic Left Shift
In this shift, each bit is moved to the left one by one. The empty least significant bit (LSB) is filled with zero, and the most significant bit (MSB) is rejected same as the Left Logical Shift. However, arithmetic left shift differs conceptually in that it is specifically interpreted as multiplication by two, especially regarding signed integer operations, whereas logical left shift does not inherently assume numeric interpretation.
Usage: Used for multiplying signed binary numbers by powers of 2.
Example: Let's take a signed 8-bit binary number in two's complement form: 11111111 (which represents -1 in decimal). If we perform an arithmetic shift left:
- Before Shift: 11111111 (-1 in decimal)
- After Arithmetic Shift Left: 11111110 (-2 in decimal)
2. Arithmetic Right Shift
In this shift, each bit is moved to the right one by one and the least significant(LSB) bit is rejected and the empty most significant bit(MSB) is filled with the value of the previous MSB.
Arithmetic Right ShiftUsage: Used for dividing signed binary numbers by powers of 2.
Example: Let's take a signed 8-bit binary number in two's complement form: 11111111 (which represents -1 in decimal). If we perform an arithmetic shift right:
- Before Shift: 11111111 (-1 in decimal)
- After Arithmetic Shift Right: 11111111 (-1 in decimal)
Circular Shift
The circular shift circulates the bits in the sequence of the register around both ends without any loss of information. Following are the two ways to perform the circular shift:
1. Circular Left Shift
In this micro shift operation each bit in the register is shifted to the left one by one. After shifting, the LSB becomes empty, so the value of the MSB is filled in there.
Circular Left ShiftUsage: Used in data encryption algorithms and certain arithmetic operations, where the shift should be cyclic.
Example: Let's take an 8-bit binary number 11010011. If we perform a circular shift left:
- Before Shift: 11010011
- After Circular Shift Left: 10100111
2. Circular Right Shift
In this micro shift operation each bit in the register is shifted to the right one by one. After shifting, the MSB becomes empty, so the value of the LSB is filled in there.
Circular Right ShiftUsage: Used in situations where rotation of bits is required, such as in encryption algorithms.
Example: Let's take the same 8-bit binary number 11010011. If we perform a circular shift right:
- Before Shift: 11010011
- After Circular Shift Right: 11101001
Symbolic Representation of Shift Microoperations
The following table presents the symbolic representation used for various shift microoperations in digital systems:
Symbolic Designation | Description |
|---|
R ← shl R | Logical Shift left register R |
R ← shr R | Logical Shift right register R |
R ← cil R | Circular shift left register R |
R ← cir R | Circular shift right register R |
R ← ashl R | Arithmetic shift left register R |
R ← ashr R | Arithmetic shift right register R |
Hardware Implementation of Logical Shift
The hardware implementation of logical shift left and right operations using multiplexers is shown below:
The following function table describes the operation of the shift logic based on the control inputs:
Select | Output |
|---|
S | H3 | H2 | H1 | H0 |
|---|
0 | A2 | A1 | A0 | IL |
1 | IR | A3 | A2 | A1 |
Application
- Math Operations: Left (
<<) and right (>>) shifts multiply or divide by powers of two, improving speed in performance-critical tasks. - Bitwise Control: Used to set, clear, or toggle bits—essential in low-level programming like device drivers.
- Data Encoding & Compression: Helps efficiently pack/unpack data, such as in bitmaps or Huffman coding.
- Cryptography: Supports key generation, encryption, and hashing by mixing bits for better security.
- Graphics Processing: Assists in handling color channels and pixel values, e.g., extracting RGB components.