Binary Shifts
A binary shift takes each bit in an 8-bit binary value and moves it a given number of positions, either leftwards or rightwards. The value stays 8 bits wide, so any bit pushed past either end is discarded.
When the bits move, gaps appear at one end. Every gap is filled with a 0 โ never with a 1, and never with a bit that fell off the other end.
To carry out a left shift of n places:
For example, left shift 00010110 by 3 places. Each bit moves three columns to the left, the three bits at the left-hand end (000) pass out of the 8-bit value, and three 0s drop into the right-hand end. The result is 10110000.
To carry out a right shift of n places:
For example, right shift 01101000 by 3 places. The three bits at the right-hand end (000) drop out, the remaining bits 01101 slide three columns to the right to become 00001101, and the three new left-hand positions are filled with 0s.
A shift is only fully described when you give both the direction and the number of places. A "shift of three" could mean three places left or three places right, and those two answers are completely different, so the direction matters just as much as the count.
Binary shifts in this topic are carried out on positive whole numbers only. Every gap is filled with a 0, so you never treat the leftmost bit any differently from the rest.
OCR GCSE Computer Science ยท Binary Shifts