Prof. Dr. Thorsten Jungmann (last updated 2026-11-02)

Relates to DET-05 Codes, code converters and standard components

Task

Your smartphone sends data to wireless headphones via Bluetooth, and electromagnetic interference can flip single bits on the way. Bluetooth protects certain packets with a shortened Hamming code. Here, you work with the form with seven bits from the lesson. The data bits , , and carry a decimal digit in the binary-coded decimal (BCD) code, with the weight 8, and three parity bits are added:

Position1234567
Bit

With even parity, completes the positions 3, 5 and 7, the positions 3, 6 and 7, and the positions 5, 6 and 7 to an even number of ones.

a) First without the Hamming code: the digit 4 is sent in the BCD code, followed by one parity bit with even parity. Give the five bits.

b) The bit with the weight 1 of a) flips on the way. Does the receiver notice? In another transmission, the bits with the weights 4 and 2 flip instead. Does the receiver notice this, and which digit does it read?

c) Determine the Hamming distance between the digits 4 and 6, first in the BCD code, then in the BCD code with one parity bit.

d) Determine the code words with seven bits for the digits 4 and 6. What is the Hamming distance between them?

e) The receiver gets 1001000. Which bit has flipped, and which digit was sent? Which digit would the data bits have delivered without the correction?

f) The receiver gets 1000100. Which bit has flipped? Does this change the digit?

g) The digit 4 was sent, and the bits at the positions 3 and 5 have flipped: the receiver gets 1011000. Which bit does the receiver invert, and what does it deliver?

h) Let to be the received bits. Give the expressions of the three results , and of the receiver. Then design the correction of the bit at position 3 with an output of a 3-to-8 decoder and an XOR gate.

◀️ Back to the task


Solution

Given

Given explicitly:

  • the positions of the parity bits , , and of the data bits , , , , with even parity
  • a) and b) the digit 4 with one parity bit, and the bits that flip
  • c) and d) the digits 4 and 6
  • e), f) and g) the received code words

Known:

  • Binary-coded decimal (BCD) code (DET-05)
  • Parity bit with even parity and Hamming distance (DET-05)
  • Hamming code with seven bits: positions, sets, finding the flipped bit (DET-05)
  • The XOR operation delivers a 1 for an odd number of ones (DET-03)
  • Parity bits and receiver as a circuit, decoder and correction (DET-05, DET-05)

Required

a) the five bits
b) whether the receiver notices each error, and the digit that it reads in the second case
c) the two Hamming distances
d) the two code words and their Hamming distance
e) the flipped bit, the digit sent and the digit without the correction
f) the flipped bit and whether the digit changes
g) the bit that the receiver inverts, and what it delivers
h) the expressions of the results and the correction of position 3

a) One parity bit

The digit 4 is 0100 in the BCD code (DET-05, 1.3). It has one 1, an odd number, so the parity bit with even parity is 1 (DET-05, 2.1). The five bits are 0100 1.

b) One and two flipped bits

If the bit with the weight 1 flips, the receiver gets 0101 1. It counts three ones, an odd number, so it notices the error, but it cannot tell which bit has flipped.

If the bits with the weights 4 and 2 flip, it gets 0010 1. It counts two ones, an even number, and notices nothing. It reads 0010, the digit 2. Two flipped bits go unnoticed (DET-05, 2.1).

c) Hamming distance

The Hamming distance is the number of positions in which two code words differ (DET-05, 2.1). In the BCD code, 0100 and 0110 differ only in the bit with the weight 2: distance 1. So one flipped bit turns one valid digit into the other, and nothing reveals it.

With the parity bit, the code words are 0100 1 and 0110 0. They differ in the bit with the weight 2 and in the parity bit: distance 2. One flipped bit no longer leads from one valid code word to another.

d) Code words with seven bits

Each parity bit is 1 if its three data bits contain an odd number of ones (DET-05, 4.3). For the digit 4, with , , and :

Position1234567
Bit
Digit 41001100

For the digit 6, with , , and :

Position1234567
Bit
Digit 61100110

So the code words are 1001100 and 1100110. They differ at the positions 2, 4 and 6: distance 3.

Check by counting the ones of each set in 1100110: positions 1, 3, 5 and 7 hold 1, 0, 1 and 0, positions 2, 3, 6 and 7 hold 1, 0, 1 and 0, positions 4, 5, 6 and 7 hold 0, 1, 1 and 0; each set has an even number of ones ✓

The distances 1, 2 and 3 are those of the table in the lesson (DET-05, 2.1): with 3, a code can correct one flipped bit or detect two.

e) Finding the flipped bit

The receiver forms the XOR over each set of four positions, the parity bit included (DET-05, 4.3). For , , , , , and :

Read with the weights 1, 2 and 4, the results give : the bit at position 5 has flipped. The receiver inverts it and gets 1001100. The data bits at the positions 3, 5, 6 and 7 are 0100, the digit 4.

Without the correction, the data bits of 1001000 are 0000, the digit 0, a valid digit that the data bits alone would not reveal as wrong.

f) A flipped parity bit

For , , , , , and :

The results give 4: the bit at position 4 has flipped, a parity bit. The data bits at the positions 3, 5, 6 and 7 are still 0100, so the digit 4 stays correct. The receiver finds the error all the same.

g) Two flipped bits

For , , , , , and :

The results give . The receiver takes this for the position of a single flipped bit and inverts bit 6, which was correct. It delivers 1011010, with the data bits 1010. This is not a valid digit in the BCD code. Now the bits at the positions 3, 5 and 6 are wrong.

So this code corrects one flipped bit or detects two, but it cannot do both at once (DET-05, 2.2). A receiver that only detects errors would see that the results are not all 0, and it would reject the code word.

h) Receiver and correction

Each result is the XOR over its set of four positions (DET-05, 4.3):

At the inputs of a 3-to-8 decoder with the weights 1, 2 and 4, the three results set exactly the output with the number of the flipped bit (DET-05, 3.2). Each output is a minterm of the results (DET-05, 3.1). For position 3, the code word is 011 for the weights 4, 2 and 1:

An XOR gate combines the received bit with this output: it passes the bit if and inverts it if (DET-05, 4.3):

Check for the case of e), with , , and :

So : bit 3 stays as it is ✓

In the simulation, the parity generator forms the parity bits, each electric line can be flipped, and the receiver and the decoder find the flipped bit. The simulation starts with the digit 4 and a flip at position 5, the case of e). Switch the flip inputs: with one flip, the corrected data bits always show the digit that was sent. With the flips at 3 and 5, the case of g), they do not.

Simulation of the Hamming code with seven bits: parity generator, flip inputs, receiver, a demultiplexer as a 3-to-8 decoder and the correction of the data bits; with the digit four and the bit at position 5 flipped, the results show five, and the corrected data bits are the digit four again
Simulation of the Hamming code with seven bits: parity generator, flip inputs, receiver, a demultiplexer as a 3-to-8 decoder and the correction of the data bits; with the digit four and the bit at position 5 flipped, the results show five, and the corrected data bits are the digit four again

Open in the simulator