Convert between positive hexadecimal and positive binary

Data Representation, Conversion & Transmission – Cambridge IGCSE Computer Science (0478)

1. Why Converting Between Number Systems Matters

  • Computers store everything as binary (base‑2).
  • Human‑readable forms such as hexadecimal (base‑16) and denary (base‑10) are used for:
    • Memory addresses and machine code
    • Debugging and exam questions
    • Colour values in graphics
    • Quick arithmetic with large binary numbers
  • Mastery of these conversions is an explicit requirement of the IGCSE syllabus (AO1, AO2, AO3).

2. Number‑System Overview (Syllabus 1.1)

SystemBaseDigits UsedTypical Use
Denary (Decimal)100–9Everyday arithmetic, exam input/output
Binary20, 1Memory, logic circuits, low‑level programming
Hexadecimal160–9, A–FCompact binary representation, addresses, colour codes

3. Core Conversion Tables

3.1 Hexadecimal ↔ Binary (4‑bit “nibble” mapping)

HexBinary (4 bits)
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001
A1010
B1011
C1100
D1101
E1110
F1111

3.2 Powers of 2 (Binary ↔ Decimal)

2ⁿDecimal Value
2⁰1
2
4
8
2⁴16
2⁵32
2⁶64
2⁷128
2⁸256

3.3 Powers of 16 (Hexadecimal ↔ Decimal)

16ⁿDecimal Value
16⁰1
16¹16
16²256
16³4 096

4. Step‑by‑Step Conversion Procedures

4.1 Hexadecimal → Binary

  1. Write the hexadecimal number.
  2. Replace each hex digit with its 4‑bit binary equivalent (Table 3.1).
  3. Concatenate the groups – the result is the full binary string.

4.2 Binary → Hexadecimal

  1. Write the binary number.
  2. Group bits in fours starting from the right. Pad the left‑most group with leading 0’s if needed.
  3. Convert each 4‑bit group to the matching hex digit (Table 3.1).
  4. Write the hex digits from left to right.

4.3 Decimal → Binary (Positive Integers)

  1. Find the highest power of 2 ≤ the decimal number.
  2. Write a 1 for that power, subtract its value, and continue with the next lower power.
  3. Write 0 for any power that is not used.
  4. The series of 1’s and 0’s, from the highest power down to 2⁰, is the binary representation.

4.4 Binary → Decimal (Positive Integers)

  1. Write the binary number with the least‑significant bit on the right.
  2. Multiply each bit by its corresponding power of 2 (2⁰, 2¹, 2², …).
  3. Sum the products – the total is the decimal value.

4.5 Decimal ↔ Hexadecimal (Positive Integers)

  • Decimal → Binary (4.3) → Hexadecimal (4.2).
  • Hexadecimal → Binary (4.1) → Decimal (4.4).

5. Binary Arithmetic, Overflow & Shifts (AO2/AO3)

5.1 Binary Addition (with Carry)

ABCarry‑inSumCarry‑out
00000
00110
01010
01101
10010
10101
11001
11111

5.2 Detecting Unsigned Overflow

  • When adding two n‑bit unsigned numbers, overflow occurs if a carry is generated out of the most‑significant bit (MSB).
  • In practice: if the result needs more than n bits, discard the left‑most bit and set the overflow flag.

5.3 Logical Shift Operations (Only logical shifts are required for IGCSE)

  • Logical left shift (<<): move all bits one position left, insert a 0 at the right‑most position. Equivalent to multiplying by 2 (unsigned).
  • Logical right shift (>>): move all bits one position right, insert a 0 at the left‑most position. Equivalent to integer division by 2 (floor) for unsigned numbers.
  • Bits shifted out are discarded; vacated positions are filled with 0s.

5.4 Two’s‑Complement (Signed Integers)

  1. Choose a word size (e.g., 8‑bit, 16‑bit).
  2. Positive numbers: write the binary form and pad with leading 0s to the chosen size.
  3. Negative number –N:
    • Write the binary of the magnitude N, padded to the word size.
    • Invert every bit (0→1, 1→0).
    • Add 1 to the inverted pattern.
  4. The MSB now acts as the sign bit (0 = positive, 1 = negative).

5.5 Detecting Overflow in Two’s‑Complement Addition

  • Overflow occurs when the carry into the sign bit differs from the carry out of the sign bit.
  • Equivalently: adding two positives yields a negative, or adding two negatives yields a positive.

6. Data Representation Beyond Numbers

6.1 Text – ASCII & Unicode

  • IGCSE focuses on the 7‑bit ASCII table (0–127). Each character = one byte (8 bits, the leading bit is 0).
  • Example: A = 65₁₀ = 0100 0001₂ = 41₁₆.
  • Unicode (16‑bit) is mentioned only briefly; it extends the range to > 65 536 characters.

6.2 Sound – Sample Rate, Bit Depth & Channels

ParameterTypical ValueExplanation
Sample rate44 100 Hz (CD quality)Number of samples taken per second.
Bit depth16 bitsPrecision of each sample (dynamic range).
Channels1 (mono) or 2 (stereo)Independent audio streams.

File‑size formula (uncompressed):

Size (bits) = Sample rate × Bit depth × Channels × Duration (seconds)

Convert to bytes by dividing by 8, then to kilobytes (KB) by dividing by 1 024.

6.3 Images – Pixels, Colour Depth & Resolution

  • Resolution: width × height (number of pixels).
  • Colour depth: bits per pixel (bpp). Common values:
    • 1 bpp – black & white
    • 8 bpp – 256 colours (indexed colour)
    • 24 bpp – true colour (8 bits for each of R, G, B)

Uncompressed image file‑size formula:

Size (bits) = Width × Height × Colour depth

Again, divide by 8 for bytes and by 1 024 for KB.

6.4 Compression

  • Lossless compression (e.g., Run‑Length Encoding – RLE): data can be restored exactly.
    • RLE example: AAAAABBC5A2B1C.
  • Lossy compression (e.g., JPEG for images, MP3 for sound): some information is discarded to achieve higher compression ratios. The original cannot be perfectly reconstructed.
  • Typical exam question: calculate the compressed size given a compression ratio (e.g., “image is compressed to 25 % of its original size”).

6.5 File‑Size Calculations – Quick Reference

Data typeFormula (bits)Example
Text (ASCII)Characters × 8120 characters → 960 bits = 120 bytes
Sound (uncompressed)Sample rate × Bit depth × Channels × Seconds44 100 × 16 × 2 × 30 = 42 470 400 bits ≈ 5 MB
Image (uncompressed)Width × Height × Colour depth800 × 600 × 24 = 11 520 000 bits ≈ 1 406 KB
Compressed fileOriginal size × Compression ratio1 406 KB × 0.25 = 351.5 KB

7. Data Transmission (Syllabus 1.2)

7.1 Packets & Packet Switching

  • A packet = header + payload + trailer.
    • Header: source/destination address, sequence number, error‑check code.
    • Payload: the actual data.
    • Trailer: often a checksum or CRC.
  • Packet switching breaks data into packets that travel independently through a network, using the most efficient route at each node.
  • Contrast with circuit switching (e.g., traditional telephone networks) where a dedicated path is reserved for the whole call.

7.2 USB (Universal Serial Bus)

  • Serial communication standard used for keyboards, mice, flash drives, etc.
  • Key points for the exam:
    • Supports hot‑plugging and plug‑and‑play.
    • Data transferred in packets; each packet contains a PID (packet identifier) and payload.
    • Typical speeds: USB 1.1 = 12 Mbps, USB 2.0 = 480 Mbps, USB 3.0 = 5 Gbps.

7.3 Error Detection & Correction

  • Parity bit (even or odd):
    • Add one extra bit so that the total number of 1’s is even (even parity) or odd (odd parity).
    • Detects any single‑bit error.
  • Checksum (simple additive):
    • Sum all data bytes, discard overflow beyond 8 bits, and send the 8‑bit result.
    • Receiver adds the received checksum; a non‑zero result indicates an error.
  • ARQ – Automatic Repeat reQuest (Stop‑and‑Wait):
    • Sender transmits a packet and waits for an ACK (acknowledgement).
    • If no ACK within a timeout, the packet is retransmitted.

7.4 Basic Encryption (Syllabus 1.2)

  • Symmetric (private‑key) encryption – same key for encryption and de‑cryption. Example used in exams: Caesar cipher (shift each letter by a fixed number).
  • Asymmetric (public‑key) encryption – a public key encrypts, a private key decrypts. Only the principle (pair of keys) is required for IGCSE.
  • Key idea for marks: state that encryption scrambles data to keep it secret; de‑cryption restores the original.

8. Worked Examples (All Core Topics)

8.1 Hexadecimal → Binary

Convert 2F3A₁₆ to binary.

  1. 2 → 0010, F → 1111, 3 → 0011, A → 1010.
  2. Result: 0010 1111 0011 1010₂ (16 bits).

8.2 Binary → Hexadecimal

Convert 10110111001₂ to hexadecimal.

  1. Group from the right: 1 0110 1110 01 → pad leftmost group → 0001 0110 1110 0001.
  2. 0001 → 1, 0110 → 6, 1110 → E, 0001 → 1.
  3. Result: 16E1₁₆.

8.3 Decimal → Binary

Convert 45₁₀ to binary (8‑bit).

  1. 32 (2⁵) ≤ 45 → write 1, remainder 13.
  2. 16 (2⁴) > 13 → write 0.
  3. 8 (2³) ≤ 13 → write 1, remainder 5.
  4. 4 (2²) ≤ 5 → write 1, remainder 1.
  5. 2 (2¹) > 1 → write 0.
  6. 1 (2⁰) ≤ 1 → write 1.
  7. Binary (8‑bit) = 0010 1101₂.

8.4 Binary → Decimal

Convert 11001011₂ to decimal.

  1. 1·2⁷ + 1·2⁶ + 0·2⁵ + 0·2⁴ + 1·2³ + 0·2² + 1·2¹ + 1·2⁰
  2. = 128 + 64 + 0 + 0 + 8 + 0 + 2 + 1 = 203₁₀.

8.5 Two’s‑Complement (8‑bit) – Negative Number

Find the 8‑bit two’s‑complement of ‑45.

  1. 45 → binary 0010 1101.
  2. Invert → 1101 0010.
  3. Add 1 → 1101 0011.
  4. Result: 1101 0011₂ (MSB = 1 ⇒ negative).

8.6 Detecting Unsigned Overflow

Add two 8‑bit unsigned numbers: 1101 0110 (214) + 0110 1011 (107).

  • Binary addition gives 1 0100 0011 (9 bits). Discard the left‑most carry → 0100 0011 (67).
  • A carry out of the MSB occurred → overflow flag set.

8.7 Logical Shift Example

Logical left‑shift 0010 1101 (45) by one position:

  • Result: 0101 1010₂ = 90₁₀.

Logical right‑shift the same value by one position:

  • Result: 0001 0110₂ = 22₁₀.

8.8 Text Representation

What is the ASCII code for the character G?

  • Decimal = 71, Binary = 0100 0111, Hex = 47₁₆.

8.9 Sound File Size

Calculate the size of a 30‑second mono recording sampled at 44 100 Hz with 16‑bit depth.

  • Size (bits) = 44 100 × 16 × 1 × 30 = 21 235 200 bits.
  • Bytes = 2 654 400 ≈ 2 . 53 MB (divide by 1 048 576).

8.10 Image File Size & Compression

A colour image is 800 × 600 pixels, 24‑bit colour depth. Find the uncompressed size and the size after 75 % compression.

  • Uncompressed bits = 800 × 600 × 24 = 11 520 000 bits → 1 440 000 bytes ≈ 1 . 41 MB.
  • Compressed size = 25 % of original = 0.25 × 1 . 41 MB ≈ 0 . 35 MB.

8.11 Packet‑Switching vs Circuit‑Switching

Explain one advantage of packet switching over circuit switching.

  • Packet switching makes more efficient use of network resources because each packet can take the most suitable route, allowing many communications to share the same physical links simultaneously.

8.12 Parity Error Detection

Transmit the 8‑bit data 10110010 with even parity. What parity bit is added, and will a single‑bit error be detected?

  • Number of 1’s = 4 (already even) → parity bit = 0.
  • Even‑parity scheme detects any single‑bit error because it would change the parity to odd.

8.13 Simple Caesar Cipher

Encrypt the word “DOG” using a shift of 3 (A → D).

  • D → G, O → R, G → J → ciphertext “GRJ”.

9. Common Pitfalls & How to Avoid Them

  • Padding errors: Always make the leftmost binary group a full nibble (4 bits) when converting to hex.
  • Order mix‑up: Keep the original left‑to‑right order; never reverse the digit sequence after conversion.
  • Overflow confusion: Remember overflow is about exceeding the chosen word size, not about the mathematical result.
  • Two’s‑complement sign: The MSB is the sign bit; a leading 1 indicates a negative value, not “‑1”. Verify by converting back to decimal.
  • Logical vs arithmetic shift: IGCSE requires logical shifts only – always insert 0s, never copy the sign bit.
  • File‑size units: Use 1 KB = 1 024 bytes, 1 MB = 1 024 KB when converting bits to the usual storage units.

10. Quick Reference Summary

10.1 Conversion Cheat‑Sheet

TaskFast Method
Hex → BinaryReplace each hex digit using Table 3.1.
Binary → HexGroup bits in fours (pad left), then use Table 3.1.
Decimal → BinaryRepeated division by 2, record remainders (reverse order).
Binary → DecimalSum 2ⁿ for each 1‑bit (n = position index).
Decimal ↔ HexUse Decimal → Binary → Hex or Hex → Binary → Decimal.

10.2 Binary Arithmetic Essentials

  • Addition uses the truth‑table (see 5.1). Carry out of MSB = unsigned overflow.
  • Logical left shift = × 2, logical right shift = ÷ 2 (floor) for unsigned numbers.
  • Two’s‑complement negative = invert bits + 1; overflow detection = carry‑in ≠ carry‑out of sign bit.

10.3 Data‑Representation Formulas

  • Image size (bits) = width × height × colour depth.
  • Sound size (bits) = sample rate × bit depth × channels × duration.
  • Compressed size = original size × compression ratio.
  • ASCII character = 8 bits (7‑bit code + leading 0).

10.4 Transmission Essentials

  • Packet = header + payload + trailer.
  • Parity (even/odd) detects single‑bit errors.
  • Checksum = 8‑bit sum of data bytes (mod 256).
  • ARQ (Stop‑and‑Wait) = send → wait for ACK → resend if timeout.
  • Symmetric encryption (e.g., Caesar) uses the same key; asymmetric uses a key pair.

Create an account or Login to take a Quiz

40 views
0 improvement suggestions

Log in to suggest improvements to this note.