---
title: "Construct a (7,4) Hamming code"
subject: "Data Communication"
chapter: 8
key: "semester_5/data_communication:hamming-74-construct"
source: https://www.bctengineer.com/q/semester_5/data_communication/hamming-74-construct
site: BCT Engineering
---

# Construct a (7,4) Hamming code

Data Communication · Chapter 8: Information Theory and Coding

- Asked in: 2076 Chaitra, 8 marks
- Video: [Unit 5 L6.3 | Linear Block code | Generator Matrix For (7,4) Hamming Code | Draw encoder for LBC](https://www.youtube.com/watch?v=gX2Y8avOeVI) — Techno Tutorials ( e-Learning)
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/data_communication/hamming-74-construct
- Whole chapter: https://www.bctengineer.com/md/semester_5/data_communication/chapter-8

## Question

Construct a (7,4) Hamming code using a 4×4 generation matrix for any arbitrary message.

## Short answer

The (7,4) Hamming code uses generator matrix G = [I4 | P] where P gives parity bits p1 = d1⊕d3⊕d4, p2 = d1⊕d2⊕d3, p3 = d2⊕d3⊕d4. Encoding message 1011 yields codeword 1011100. Parity-check matrix H = [P^T | I3] enables single-error correction with syndrome matching the erroneous bit column.

## Answer

A **(7,4) Hamming code** encodes 4 data bits into 7 bits by adding 3 parity bits. It has d_min = 3, so it corrects any single-bit error.

#### Generator matrix (4 × 4 identity + 4 × 3 parity part)
G = [I₄ | P]:

```text
      | 1 0 0 0 : 1 1 0 |
 G =  | 0 1 0 0 : 0 1 1 |
      | 0 0 1 0 : 1 1 1 |
      | 0 0 0 1 : 1 0 1 |
```
Codeword c = d·G (mod 2) = [d1 d2 d3 d4 | p1 p2 p3], where
- p1 = d1 ⊕ d3 ⊕ d4
- p2 = d1 ⊕ d2 ⊕ d3
- p3 = d2 ⊕ d3 ⊕ d4

#### Encoding an arbitrary message d = 1011
c = row 1 ⊕ row 3 ⊕ row 4
= 1000110 ⊕ 0010111 ⊕ 0001101 = **1011100**

(Check by equations: p1 = 1⊕1⊕1 = 1, p2 = 1⊕0⊕1 = 0, p3 = 0⊕1⊕1 = 0.)

#### Parity-check matrix H = [Pᵀ | I₃]
```text
      | 1 0 1 1 : 1 0 0 |
 H =  | 1 1 1 0 : 0 1 0 |
      | 0 1 1 1 : 0 0 1 |
```
For every codeword, syndrome s = c·Hᵀ = 000.

#### Error detection and correction
Suppose bit 3 is received wrongly: r = 1001100.
- s1 = r1⊕r3⊕r4⊕r5 = 1⊕0⊕1⊕1 = 1
- s2 = r1⊕r2⊕r3⊕r6 = 1⊕0⊕0⊕0 = 1
- s3 = r2⊕r3⊕r4⊕r7 = 0⊕0⊕1⊕0 = 1

s = 111, which equals column 3 of H, so bit 3 is in error. Flip it to get 1011100 and read the message 1011.

#### The sixteen codewords
0000000, 0001101, 0010111, 0011010, 0100011, 0101110, 0110100, 0111001, 1000110, 1001011, 1010001, 1011100, 1100101, 1101000, 1110010, 1111111. The minimum non-zero weight is 3, so d_min = 3.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the form of the generator matrix used?
   A. G = [I4 | P] with P a 4 x 3 parity part
   B. G = [P | I7]
   C. A 7 x 7 identity
   D. G = [I3 | P] with 3 rows
   Answer: A. G has 4 rows and 7 columns: the 4 x 4 identity plus a 4 x 3 parity part. (Key point: Generator matrix form)

2. What is the codeword for d = 1011?
   A. 1011010
   B. 1011100
   C. 1011001
   D. 1010110
   Answer: B. Row 1 xor row 3 xor row 4 = 1000110 xor 0010111 xor 0001101 = 1011100. (Key point: Encoding)

3. For r = 1001100, the syndrome is 111. Which bit is in error?
   A. Bit 1
   B. Bit 7
   C. Bit 5
   D. Bit 3
   Answer: D. 111 equals column 3 of H = [P^T | I3], so bit 3 is flipped back to give 1011100. (Key point: Syndrome)

4. Why can this code correct any single-bit error?
   A. d_min = 3, so it corrects floor((3-1)/2) = 1 error
   B. d_min = 7
   C. It has 3 parity bits so corrects 3 errors
   D. It uses retransmission
   Answer: A. The minimum non-zero weight is 3, giving single-error correction. (Key point: Minimum distance)

## Related in Data Communication

- [Forward error correction using Hamming code](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Afec-hamming) — Data Communication, chapter 8
- [Hamming codes and their properties](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ahamming-code-properties) — Data Communication, chapter 8
- [Minimum Hamming distance; find k and n](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Amin-hamming-k-n) — Data Communication, chapter 8
- [(6,3) block code words, weights, dmin](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ablock-code-63-matrix-weights) — Data Communication, chapter 8
- [Design a (6,3) block code word](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Ablock-code-63-design) — Data Communication, chapter 8, asked 3×
- [Design a C(8,4) linear block code](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Alinear-block-code-84) — Data Communication, chapter 8

## Related in other subjects

- [Hamming weight and distance; (7,4) cyclic code for 1011](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Ahamming-weight-cyclic-1011) — Communication Systems, chapter 8, asked 2×
- [Hamming distance and weight; (6,3) code check for 100101](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Ahamming-6-3-h-100101) — Communication Systems, chapter 8
- [Speech characteristics and 7-bit Hamming code](https://www.bctengineer.com/question.md?key=semester_7%2Fwireless_communication%3Aspeech-hamming-code) — Wireless Communication, chapter 6
- [Hamming weight and distance; validate code 100011](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Ahamming-6-3-h-100011) — Communication Systems, chapter 8
