Describe practical applications where Binary Coded Decimal (BCD) and Hexadecimal are used

1.1 Data Representation – Overview

1.1.1 Binary Magnitudes and Prefixes

Computers work in powers of two. Two families of prefixes are used when describing memory or data sizes.

Prefix (binary)SymbolValue
kibiKi1 KiB = 210 bytes = 1 024 B
mebiMi1 MiB = 220 bytes = 1 048 576 B
gibiGi1 GiB = 230 bytes = 1 073 741 824 B
tebiTi1 TiB = 240 bytes

For everyday discussion the decimal prefixes kilo (k = 10³), mega (M = 10⁶) and giga (G = 10⁹) are also used, but they do not map exactly to the binary values. Knowing the difference is essential when converting file‑size, bandwidth or storage‑requirement figures.

1.1.2 Number‑System Conversions (Exam‑Ready Algorithms)

Cambridge examinations require you to move fluently between binary, decimal, hexadecimal and Binary‑Coded Decimal (BCD). The following pseudo‑code is short enough to be memorised.

Binary → Decimal

function binToDec(b):

dec = 0

for each bit from left‑most to right‑most:

dec = dec * 2 + bit

return dec

Decimal → Binary (repeated division)

function decToBin(n):

bits = []

while n > 0:

bits.append(n % 2) // remainder is next bit

n = n // 2

return reverse(bits) // most‑significant bit first

Binary ↔ Hexadecimal (grouping nibbles)

  • Binary → Hex: split the binary string into groups of four bits (starting from the right) and replace each group with its hex digit (0‑9, A‑F).
  • Hex → Binary: replace each hex digit with its 4‑bit binary equivalent.

Decimal → BCD

function decToBCD(n):

bcd = []

for each decimal digit d in string representation of n:

bcd.append( binary representation of d using 4 bits )

return concatenate(bcd)

BCD ↔ Binary (digit‑wise)

  • BCD → Binary: treat each 4‑bit nibble as a separate decimal digit and concatenate the nibbles.
  • Binary → BCD: first convert the binary number to decimal, then apply the Decimal → BCD routine.

1.1.3 Binary Arithmetic (Addition, Subtraction & Overflow)

All binary arithmetic in the syllabus is performed on fixed‑width words (usually 8‑, 16‑ or 32‑bit). The rules below are sufficient for exam questions.

Unsigned addition

  1. Align the numbers, add column‑wise, write the sum bit and carry to the next column.
  2. If a carry is produced from the most‑significant bit (MSB) it is discarded (wrap‑around).
  3. Overflow is detected when a carry‑out of the MSB is 1.

Example (8‑bit): 1101 0110₂ (214) + 0011 1011₂ (59)

  1101 0110

+ 0011 1011

------------

0000 11101 (carry out of MSB = 1 → result = 0010 11101₂ = 13, overflow)

Two’s‑complement subtraction

  1. To subtract B from A, form the two’s‑complement of B (invert all bits, add 1).
  2. Add this value to A using the same routine as for addition.
  3. Ignore any final carry‑out; the sign of the result is given by the MSB.
  4. Overflow occurs when the carry into the sign bit differs from the carry out of the sign bit.

Example (8‑bit): +25 – 45

0001 1001 (+25)

1101 0011 (two’s‑complement of 45 = invert 0010 1101 → 1101 0010, +1 → 1101 0011)

----------

1110 1100 (result = –20, MSB = 1, no overflow because carries into/out of sign bit are equal)

1.1.4 Signed Binary – Two’s Complement Summary

  • For an n‑bit word the range is –2n‑1 … 2n‑1 – 1.
  • Negative of a number: invert all bits (one’s complement) and add 1.
  • When adding two numbers of the same sign, a different sign in the result indicates overflow.

1.1.5 Character Encodings

Text is stored as numeric codes. The two most common systems are:

EncodingBits per code pointRangeTypical use in exams
ASCII7 bits (usually stored in an 8‑bit byte)0 – 127 (basic Latin)Identify control characters, convert between character and decimal/hex.
Unicode (UTF‑8)1‑4 bytes per code point0 – 0x10FFFF (all world scripts)Explain why a character may need more than one byte.

First 32 ASCII codes are control characters (e.g., 0x00 NUL, 0x0A LF). Knowing these values helps when analysing protocol headers or debugging text‑based data.

1.1.6 Binary‑Coded Decimal (BCD)

BCD stores each decimal digit (0‑9) as a separate 4‑bit nibble. It uses more bits than a pure binary representation but guarantees a direct decimal view, which is valuable in many real‑world systems.

Key Applications

  • Financial & Accounting systems – Exact decimal representation avoids rounding errors inherent in binary floating‑point.
  • Digital clocks, timers and seven‑segment displays – Drivers receive BCD values, simplifying the mapping to segment patterns.
  • Calculator firmware (historical) – Intermediate results were kept in BCD to ensure the displayed digits matched the stored value.
  • Embedded key‑pads – Numeric entry is naturally decimal; storing it as BCD removes the need for an extra conversion step.
  • Communication protocols – GSM SMS timestamps, some RFID tags and other low‑power protocols encode numeric fields in BCD.

BCD Arithmetic

When adding BCD numbers each nibble must stay ≤ 9. After a normal binary addition, any nibble that exceeds 9 is corrected by adding 6 (0x06). This is known as the “BCD correction” step.

Example: Add 0x27 (decimal 27) and 0x58 (decimal 58).

0010 0111 (0x27)

+ 0101 1000 (0x58)

------------

0111 1111 (binary sum = 0x7F)

Nibble‑wise correction:

lower nibble = 0xF (>9) → add 0x6 → 0xF + 0x6 = 0x15 → write 0x5, carry 1

upper nibble = 0x7 + carry 1 = 0x8 (≤9, no further correction)

Result = 0x85 → decimal 85 (correct answer).

BCD Overflow

Overflow is detected when a corrected nibble still exceeds 9 after the correction step, or when a carry is generated out of the most‑significant digit.

1.1.7 Hexadecimal

Hexadecimal (base‑16) uses the symbols 0‑9 and A‑F, each representing a 4‑bit binary group (a nibble). It is the preferred notation for low‑level programming, debugging and hardware documentation.

Key Applications

  • Memory addressing – Addresses are shown in hex because each digit maps directly to a nibble, making offset calculations easy.
  • Machine code & assembly language – Opcodes, immediate operands and bit‑masks are written in hex to keep listings compact.
  • Web colour notation – Colours are expressed as #RRGGBB where each pair of hex digits gives the intensity of red, green and blue.
  • Debugging & diagnostics – Hex dumps of files, memory blocks or network packets let engineers spot patterns quickly.
  • Network protocols – MAC addresses, IPv6 addresses and many header fields are written in hex.
  • Microcontroller configuration – Registers and I/O ports are set with hex literals (e.g., 0x3F).

Hexadecimal Arithmetic (quick tips)

  • Perform addition/subtraction exactly as in decimal, but use base 16.
  • When a digit sum ≥ 16, write the remainder (sum – 16) and carry 1 to the next higher digit.
  • For subtraction, borrow 1 (i.e., 16) from the next higher digit when needed.

1.1.8 Multimedia Data Representation

The syllabus expects you to understand how images, video and sound are stored.

Images – Bitmap vs Vector

  • Bitmap (raster) images store colour information for each pixel.

    • Colour depth = bits per pixel (bpp). Common depths: 1 bpp (black‑white), 8 bpp (256 colours), 24 bpp (true colour, 8 bits for R, G, B).
    • File size ≈ width × height × colour‑depth / 8 bytes.

  • Vector images store geometric primitives (lines, curves) and are resolution‑independent. No direct colour‑depth calculation; size depends on number of objects.

Sound – Sampling and Quantisation

  • Sample rate (Hz) = number of amplitude measurements per second (e.g., 44 200 Hz for CD quality).
  • Bit depth = bits used for each sample (e.g., 16 bits gives 65 536 possible amplitude levels).
  • File size (uncompressed) ≈ duration × sample‑rate × bit‑depth × channels / 8 bytes.

1.1.9 Data Compression

Two broad categories are required for the exam.

Lossless compression

  • Original data can be perfectly reconstructed.
  • Typical algorithms: Run‑Length Encoding (RLE), Huffman coding, LZ77/LZ78 (used in ZIP, PNG).
  • Best for text, executable files and any data where loss of information is unacceptable.

Lossy compression

  • Some information is permanently discarded to achieve higher compression ratios.
  • Common in audio (MP3, AAC) and video (MPEG‑4, H.264) where perceptual models hide the loss.
  • Not suitable for data that must remain exact (e.g., source code, financial records).

RLE Example

Original byte stream: AAABBBBBCCDDDDDDDD

RLE representation (value, count): (A,3)(B,5)(C,2)(D,8)

If the count field is stored in a single byte, the compressed size is 8 bytes versus the original 16 bytes – a 50 % reduction.

1.1.10 Practical Use of Binary Prefixes in Storage

  • Operating systems report file sizes using binary prefixes (KiB, MiB, GiB). Example: a 1 MiB file occupies 1 024 KiB = 1 048 576 bytes.
  • When a file is compressed, the reduction is also expressed in binary units to avoid confusion with decimal “kilobytes”.
  • Understanding these prefixes helps when estimating storage for large data sets or when interpreting the “size on disk” column in file managers.

1.1.11 Comparison of BCD and Hexadecimal

AspectBinary‑Coded Decimal (BCD)Hexadecimal
Primary goalExact decimal representationCompact representation of binary data
Typical domainFinance, time‑keeping, user‑entered numeric entrySystems programming, hardware design, networking
Storage efficiency4 bits per decimal digit (inefficient for large numbers)4 bits per hex digit (covers 0‑15 values)
Human readabilityDirectly readable as decimal digitsReadable for engineers familiar with binary groups
Common exampleAmount $123.45 → 0001 0010 0011 0100 0101 (BCD)Memory address 0x3FA7 → binary 0011 1111 1010 0111

1.1.12 Illustrative Worked Examples

Example 1 – Converting a Decimal Time to BCD

Display required: 14:35

  1. Separate digits: 1, 4, 3, 5.
  2. Convert each digit to a 4‑bit nibble:

    • 1 → 0001
    • 4 → 0100
    • 3 → 0011
    • 5 → 0101

  3. Combine: 0001 0100 0011 0101 (BCD representation of 14:35).

Example 2 – Using Hexadecimal for a Memory Map

Peripheral register at address 0x1A3C. Set the low byte to 0xFF while preserving the high byte.

unsigned short *reg = (unsigned short *)0x1A3C;

*reg = (*reg & 0xFF00) | 0x00FF; // keep high byte, set low byte to 0xFF

This demonstrates the convenience of hex literals for bit‑masking and address manipulation.

Example 3 – Binary Addition with Two’s‑Complement Subtraction

Compute -12 + 27 using 8‑bit two’s‑complement.

-12 → 1111 0100 (invert 0000 1011 → 1111 0100, add 1 → 1111 0101)

27 → 0001 1011

----------------

0000 1110 = +14 (correct result, no overflow)

Example 4 – RLE Compression of a Simple Bitmap Row

Row (binary) = 1111000011110000

RLE (value, count): (1,4)(0,4)(1,4)(0,4)

Original size = 16 bits; compressed size = 4 pairs × (1 bit + 4 bits for count) = 20 bits – in this tiny example the overhead is larger, illustrating that RLE is only efficient when long runs occur.

1.1.13 Summary

  • Binary prefixes, number‑system conversions, and two’s‑complement arithmetic are core to all exam questions on data representation.
  • BCD is chosen when exact decimal values are required (finance, clocks, simple key‑pads).
  • Hexadecimal provides a concise, human‑readable view of binary data and is ubiquitous in addressing, machine code, colour codes and networking.
  • Multimedia data (bitmap, vector, audio) and compression techniques round out the syllabus – be able to calculate sizes and explain why lossless or lossy methods are used.