Q.1
14 MarksXOR (Exclusive OR) gate: the output is 1 when the inputs are different.
XNOR (Exclusive NOR) gate: the output is 1 when the inputs are the same. It is the complement of XOR.
| A | B | XOR | XNOR |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Uses: XOR in adders, parity generators and comparators; XNOR as an equality detector.
Decimal to hexadecimal
Method: divide the number repeatedly by 16 and write the remainders; read them from bottom to top. Remainders 10 to 15 are written A to F.
Example:
| Division | Quotient | Remainder |
|---|---|---|
| 450 ÷ 16 | 28 | 2 |
| 28 ÷ 16 | 1 | 12 = C |
| 1 ÷ 16 | 0 | 1 |
Check: .
Hexadecimal to octal
Method: convert each hex digit to 4-bit binary, then regroup the bits in groups of 3 from the right, and write each group as an octal digit.
Example:
Regroup in threes from the right:
Check: , the same number. Going through binary works because 16 and 8 are both powers of 2: one hex digit is exactly 4 bits and one octal digit is exactly 3 bits.
An error correcting code adds extra (redundant) bits to the data so that the receiver can not only detect an error but also find and correct it. The most common is the Hamming code.
Parity bits needed
For data bits, the number of parity bits must satisfy . For 4 data bits, , giving a 7-bit code.
Positions
Parity bits are at positions 1, 2 and 4 (powers of 2):
| Position | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| Bit | P1 | P2 | D1 | P4 | D2 | D3 | D4 |
- P1 checks positions 1, 3, 5, 7.
- P2 checks positions 2, 3, 6, 7.
- P4 checks positions 4, 5, 6, 7.
Example: send data 1011 (even parity)
.
- P1: positions 3, 5, 7 = 1, 0, 1 (two 1s), so P1 = 0.
- P2: positions 3, 6, 7 = 1, 1, 1 (three 1s), so P2 = 1.
- P4: positions 5, 6, 7 = 0, 1, 1 (two 1s), so P4 = 0.
Code sent: 0 1 1 0 0 1 1
Correcting an error
The receiver gets 0110001 (bit 6 changed). It recomputes the checks:
- (1, 3, 5, 7) = 0, 1, 0, 1: even, so .
- (2, 3, 6, 7) = 1, 1, 0, 1: odd, so .
- (4, 5, 6, 7) = 0, 0, 0, 1: odd, so .
Error position . Bit 6 is flipped back to 1, giving 0110011, and the data 1011 is recovered. If all checks are 0, there is no error.
Other codes
- Parity bit: detects a single error but cannot correct it.
- SEC-DED Hamming code: an extra overall parity bit also detects double errors.
- CRC and Reed-Solomon codes: used in networks, CDs and QR codes.
An error correcting code such as Hamming code adds parity bits at positions 1, 2 and 4; data 1011 is sent as 0110011, and if bit 6 is received wrong, the check bits give the binary number 110 = 6, so that bit is flipped to correct it.