GCSE Computer Science Revision

Understanding Binary Shifts

Binary shifts are operations that move the bits in a binary number left or right. Understanding binary shifts is crucial in computer science for manipulating data and altering the value of numbers efficiently.

Effect of Binary Shifts

A binary shift can significantly change a number's value. Shifting to the left (<<) effectively multiplies the number by 2 for each shift, while shifting to the right (>>) divides the number by 2, discarding any fractions.

Performing Binary Shifts

To carry out a binary shift, each bit is moved one place to the left or right. For left shifts, a 0 is brought in at the rightmost position, while for right shifts, the leftmost bit is discarded, and a 0 is added at the leftmost position.

Example:

Left shift of 1011 (11 in denary): 1011 << 1 = 0110 (6 in denary)

Right shift of 1011 (11 in denary): 1011 >> 1 = 0101 (5 in denary)

Significant Bits in Binary Shifts

In binary shifts, understanding the 'most significant bit' (MSB) and 'least significant bit' (LSB) is important:

  • Most Significant Bit (MSB): The leftmost bit in the binary number, representing the highest value.
  • Least Significant Bit (LSB): The rightmost bit in the binary number, representing the lowest value.

In a left shift, bits move away from the LSB and towards the MSB. In a right shift, the opposite occurs.

Practice Exercise

Question: Perform a left and a right binary shift on the number 1101.

Answer: Left shift: 1101 << 1 = 1010. Right shift: 1101 >> 1 = 0110.