1.1 Number systems – Logical binary shift: “Perform a logical binary shift on a positive 8‑bit binary integer and understand the effect on the decimal value.”
Students must be fluent in converting between binary, decimal and hexadecimal. The table shows the first sixteen values; the exercises that follow require both directions of conversion.
| Decimal | Binary (4‑bit) | Hexadecimal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
Answers: 156₁₀ = 1001 1100₂ = 9C₁₆; 0x9C = 156₁₀ = 1001 1100₂.
-128 … +127.Find the 8‑bit two’s‑complement representation of -45:
0010 1101₂.1101 0010₂.1101 0011₂. Hence -45 = 1101 0011₂.A logical shift treats the 8‑bit word as **unsigned**. All bits are moved left (<<) or right (>>) by the required number of positions; the vacated positions are filled with 0. Any bits that move beyond the 8‑bit boundary are discarded (lost).
Bit positions are numbered from 7 (most‑significant bit, MSB) down to 0 (least‑significant bit, LSB).
Result = (value × 2ⁿ) mod 256Result = ⌊ value ÷ 2ⁿ ⌋
<<)Each left‑shift multiplies the unsigned value by 2. If a 1 is shifted out of bit 7, that bit is lost – this is the overflow condition for unsigned numbers.
| Step | Binary before shift | Binary after 1‑bit left‑shift | Decimal value |
|---|---|---|---|
| 1 | 0010 0111 | 0100 1110 | 39 × 2 = 78 |
| 2 | 0100 1110 | 1001 1100 | 78 × 2 = 156 |
| 3 (overflow) | 1001 1100 | 0011 1000 | Bits 8‑9 discarded → 56 |
>>)Each right‑shift divides the unsigned value by 2, discarding the LSB and inserting a 0 at the MSB.
| Step | Binary before shift | Binary after 1‑bit right‑shift | Decimal value |
|---|---|---|---|
| 1 | 0010 0111 | 0001 0011 | ⌊39/2⌋ = 19 |
| 2 | 0001 0011 | 0000 1001 | ⌊19/2⌋ = 9 |
| 3 | 0000 1001 | 0000 0100 | ⌊9/2⌋ = 4 |
1 shifted out of bit 7 during a left‑shift? → Overflow (value reduced modulo 256).| Feature | Logical shift | Arithmetic shift |
|---|---|---|
| Purpose | Used for **unsigned** data. | Used for **signed** two’s‑complement data. |
| Left‑shift | Identical to arithmetic left‑shift (insert 0 on the right). | Same as logical left‑shift. |
| Right‑shift | Insert 0 into the MSB. | Copy the original MSB (sign bit) into the new MSB. |
| Effect on sign | Sign is not preserved – a positive number may become negative after a right‑shift. | Sign is preserved – the number stays positive or negative. |
0010 0111).0 into the newly‑vacated position (MSB for right‑shift, LSB for left‑shift).0010 1101₂.0101 1010₂ = 90.1011 0100₂ = 180.1 left the MSB during the two shifts.1100 1011₂ (= 203₁₀).0110 0101₂ = 101.0011 0010₂ = 50.Add 150₁₀ and 120₁₀.
1001 0110₂.0111 1000₂. 1001 0110+0111 1000-----------1 0000 11100000 1110₂ = 14₁₀.1 was shifted out of the MSB, overflow has occurred (the true sum 270 exceeds 255).1110 0010₂ (MSB = 1, so negative).0111 0001₂ = 113₁₀ (now positive!).1111 0001₂ = –15₁₀, preserving negativity.0 in the vacated MSB/LSB.0011 0100₂ by one position. Write the new binary and decimal values.1100 1011₂ by two positions. Write the new binary and decimal values.1000 0001₂ does not preserve the sign of a signed 8‑bit integer.Logical shifts underpin many algorithms that appear later in the course:
Mastering logical shifts therefore makes these advanced topics much easier.
Next in the syllabus: Text, sound and images – representation of non‑numeric data (ASCII, Unicode, colour depth, sample rate). Review how binary patterns encode characters and pixel values, and notice where logical shifts are used to manipulate those patterns.
Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.