Binary Shifts
Binary Shifts
1 0 1 1 0 1 0 1
Logical
Logical & Arithmetic Left Shift
Arithmetic
● Each bit is moved one left
● The most significant bit(left most) is discarded
● A zero is added to the right
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
Logical
Logical & Arithmetic Left Shift
Arithmetic
● Each bit is moved one left
● The most significant bit(left most) is discarded
● A zero is added to the right
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
0 1 1 0 1 0 1
Logical
Logical & Arithmetic Left Shift
Arithmetic
● Each bit is moved one left
● The most significant bit(left most) is discarded
● A zero is added to the right
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
0 1 1 0 1 0 1
Logical
Logical & Arithmetic Left Shift
Arithmetic
● Each bit is moved one left
● The most significant bit(left most) is discarded
● A zero is added to the right
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
0 1 1 0 1 0 1 0
Logical
Logical & Arithmetic Left Shift
Arithmetic
● Each bit is moved one left
● The most significant bit(left most) is discarded
● A zero is added to the right
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
0 1 1 0 1 0 1 0
Logical / Arithmetic Left Shift Examples
10110101 01011010
<< 2 << 4
Logical / Arithmetic Left Shift Examples
10110101 01011010
<< 2 << 4
11010100 10100000
Logical
Logical Right Shift
● Each bit is moved one right
● The least significant bit(right most) is discarded
● A zero is added to the left
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
Logical
Logical Right Shift
● Each bit is moved one right
● The least significant bit(right most) is discarded
● A zero is added to the left
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
Logical
Logical Right Shift
● Each bit is moved one right
● The least significant bit(right most) is discarded
● A zero is added to the left
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
1 0 1 1 0 1 0
Logical
Logical Right Shift
● Each bit is moved one right
● The least significant bit(right most) is discarded
● A zero is added to the left
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
1 0 1 1 0 1 0
Logical
Logical Right Shift
● Each bit is moved one right
● The least significant bit(right most) is discarded
● A zero is added to the left
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
0 1 0 1 1 0 1 0
Logical Right Shift Examples
10110101 01011010
>> 3 >> 5
Logical Right Shift Examples
10110101 01011010
>> 3 >> 5
00011010 00000010
Arithmetic
Arithmetic Right Shift
● Each bit is moved one right
● The least significant bit(right most) is discarded
● The most significant bit is copied to the left hand side
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
Arithmetic
Arithmetic Right Shift
● Each bit is moved one right
● The least significant bit(right most) is discarded
● The most significant bit is copied to the left hand side
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
1 0 1 1 0 1 0
Arithmetic
Arithmetic Right Shift
● Each bit is moved one right
● The least significant bit(right most) is discarded
● The most significant bit is copied to the left hand side
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
1 0 1 1 0 1 0
Arithmetic
Arithmetic Right Shift
● Each bit is moved one right
● The least significant bit(right most) is discarded
● The most significant bit is copied to the left hand side
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
1 0 1 1 0 1 0
Arithmetic
Arithmetic Right Shift
● Each bit is moved one right
● The least significant bit(right most) is discarded
● The most significant bit is copied to the left hand side
● repeat for the number of shifts required...
1 0 1 1 0 1 0 1
1 1 0 1 1 0 1 0
Arithmetic Right Shift Examples
10110101 01011010
>> 2 >> 4
Arithmetic Right Shift Examples
10110101 01011010
>> 2 >> 4
11101101 00000101
Cyclic Shift (Left / Right) Cyclic
1 0 1 1 0 1 0 1
Cyclic Shift (Left / Right) Cyclic
1 0 1 1 0 1 0 1
Cyclic Shift (Left / Right) Cyclic
1 0 1 1 0 1 0 1
1 0 1 1 0 1 0
Cyclic Shift (Left / Right) Cyclic
1 0 1 1 0 1 0 1
1 0 1 1 0 1 0
Cyclic Shift (Left / Right) Cyclic
1 0 1 1 0 1 0 1
1 1 0 1 1 0 1 0
Cyclic Shift Examples
10110101 01011010
>> 2 << 4
Cyclic Shift Examples
10110101 01011010
>> 2 << 4
01101101 10100101
Summary
Logical left
Arithmetic right Cyclic
Arithmetic left
● Move all bits to the left ● Preserves the sign bit ● Move all bits along
● MSB is discarded ● Move all bits to the right ● The bit that falls off one
● Zero is add to the right ● LSB is discarded end is added back to the
● MSB is copied to the left other end