Binary Coded Decimal (BCD) and Text Coding: Parity Codes and Hamming Code, Study notes of Computer Science

The concepts of binary coded decimal (bcd) and text coding, focusing on parity codes and hamming code. Bcd is a method of representing decimal numbers in binary form, while text coding deals with representing characters in binary form. Parity codes are used for error detection in binary data transmission, while hamming code enables single errors to be detected and corrected. Examples, encoding and transmission processes, and detection and correction methods.

Typology: Study notes

2012/2013

Uploaded on 03/22/2013

dhritiman
dhritiman 🇮🇳

4.7

(6)

106 documents

1 / 22

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Section 2 Computer Codes
2.1 Binary Coded Decimal (BCD):
Definition
Widely used representation of numerical data in
which each digit of a decimal number is
represented by a 4-bit binary number
For N-digit decimal numbers, their BCD
representations require 4 * N bits
Decimal
BCD
N
B0
B1
B2
B3
0
0
0
0
0
1
0
0
0
1
2
0
0
1
0
3
0
0
1
1
4
0
1
0
0
5
0
1
0
1
6
0
1
1
0
7
0
1
1
1
8
1
0
0
0
9
1
0
0
1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download Binary Coded Decimal (BCD) and Text Coding: Parity Codes and Hamming Code and more Study notes Computer Science in PDF only on Docsity!

Section 2 – Computer Codes

2.1 Binary Coded Decimal (BCD):

Definition

  • Widely used representation of numerical data in which each digit of a decimal number is represented by a 4-bit binary number
  • For N-digit decimal numbers, their BCD representations require 4 * N bits

Decimal BCD N B 0 B 1 B 2 B 3 0 0 0 0 0 1 0 0 0 1 2 0 0 1 0 3 0 0 1 1 4 0 1 0 0 5 0 1 0 1 6 0 1 1 0 7 0 1 1 1 8 1 0 0 0 9 1 0 0 1

Example

Decimal to BCD Encoder

  • 10 inputs and 4 outputs
  • Homework: Implement the encoder using gates

S 0 S 1 S 2 S 3 S 4 S 5 S 6 S 7 S 8 S 9 B 0 B 1 B 2 B 3

S 0 S 1 Enc

S 9

B (^0)

B (^3)

2.2 Text Coding

Characters o General term used for letters, digits and punctuation o Each character is assigned a unique numerical code o How many codes are needed? o Digits (10): 0, 1, 2, 3,…, 9 o Lower case letters (26): a, b, c,…, z o Upper case letters (26): A, B, C,…, Z o Punctuation (16):. , ; :?! “ ‘ ` { } [ ] ( ) o Special characters (18): # $ € ¥ £ % ^ & * + - = \ / < > | ~ o Other characters: § © ® ¶ ± ¢ ¼ o Characters for other languages : ß â ç ê ţ Њ љ Ω ּפ

ASCII code o 7 bits allocated to store each code o 27 = 128 codes for 128 possible characters o Covers digits, lower and upper case letters, punctuation, special and other characters o Does not cover characters for other languages (accents, umlauts, fadas)

0 1 2 3 4 5 6 7 8 9 A B C D E F 0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI 1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US 2 SP! " # $ % & ' ( ) * + , -. / 3 0 1 2 3 4 5 6 7 8 9 : ; < = >? 4 @ A B C D E F G H I J K L M N O 5 P Q R S T U V W X Y Z [ \ ] ^ _ 6 ` a b c d e f g h i j k l m n o 7 p q r s t u v w x y z { | } ~ DEL

Extended ASCII

o Specified by International Standards Organization-ISO o A subset of ISO-8859 that includes several sets of characters for writing in Cyrillic, Arabic, Hebrew, etc. o Extends ASCII, including additional characters used in some West European languages such as Irish, French and German o One byte (8 bits) allocated to store each code o 28 = 256 codes for 256 possible characters o Text encoded in Extended ASCII can be transmitted through e-mail and be printed on any computer system, being accepted as basis for every text file formats o E.g. ‘a’ <=> 97 10 = 1100001 2 = 61 16

Decimal 9 7 Binary 0 1 1 0 0 0 0 1 Hexadecimal 6 1

Words (Strings)

o A word is represented as a sequence of 0 or more characters in form of a string or an array of characters o E.g. “ee201” = [‘e’, ‘e’, ‘2’, ‘0’, ‘1’] (^) ASCII = [101, 101, 50, 48, 49] 10 = [65, 65, 32, 30, 31] (^16)

Binary 0 1 1 0 0 1 0 1 Hex 6 5 Binary 0 1 1 0 0 1 0 1 Hex 6 5 Binary 0 0 1 1 0 0 1 0 Hex 3 2 Binary 0 0 1 1 0 0 0 0 Hex 3 0 Binary 0 0 1 1 0 0 0 1 Hex 3 1

2.3 Gray Codes:

Definition

  • Counting sequences that change only one bit between adjacent steps

Decimal Gray Code N G 0 G 1 G 2 G 3 0 0 0 0 0 1 0 0 0 1 2 0 0 1 1 3 0 0 1 0 4 0 1 1 0 5 0 1 1 1 6 0 1 0 1 7 0 1 0 0 8 1 1 0 0 9 1 1 0 1 10 1 1 1 1 11 1 1 1 0 12 1 0 1 0 13 1 0 1 1 14 1 0 0 1 15 1 0 0 0

Implementation:

B (^0)

G (^0)

B 1 B 2 B 3 B 4

G (^1) G 2 G 3 G (^4)

Binary Number Gray Code B 0 B 1 B 2 B 3 G 0 G 1 G 2 G 3 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 0 0 1 1 1 1 1 1 0 0 0

Gray Code to Binary Conversion

The 1-st bit of the binary code (the most significant) is the same as the 1-st bit of the corresponding Gray code

The 2-nd bit of the binary code is 1 if the 1-st bit of the binary code and the 2-nd bit of the Gray code are different and 0 if they are the same … The N-th bit of the binary code is 1 if the (N-1)-th bit of the binary code and the N-th bit of the Gray code are different and 0 if they are the same

Example

Rules: B 0 = G 0 ; BN = BN-1 ⊕ GN

G (^0)

B 0

G 1 G 2 G 3 G (^4)

B (^1) B 2 B 3 B (^4)

Examples

  • Even Parity

o E.g. ‘a’ <=ASCII=> 97 10 = 1100001 2

o E.g. 111010011100001 2

  • Odd Parity

o E.g. ‘a’ <=ASCII=> 97 10 = 1100001 2

ASCII Decimal 9 7 ASCII Binary 1 1 0 0 0 0 1 ASCII Hexa 6 1 Even Parity Code 1 1 1 0 0 0 0 1 Even Parity Code Hex E 1

Binary 1 1 1 0 1 0 0 1 1 1 0 0 0 0 1 Hexa 7 4 E 1 Even Parity Code 0 1 1 1 0 1 0 0 1 1 1 0 0 0 0 1

Even Parity Code Hex 7 4 E 1

ASCII Decimal 9 7 ASCII Binary 1 1 0 0 0 0 1 ASCII Hex 6 1 Even Parity Code 0 1 1 0 0 0 0 1 Even Parity Code Hex 6 1

Even parity bit

Even parity bit

Odd parity bit

Application

  • Transmission Error Detection

Parity Generator (^) CheckerParity

A B C

D

A

B C D

Parity Bit (^) IndicatorError

  • Notes:

o Using a single parity bit, errors in transmission of binary data sequences (words) can be detected

o Only singular errors can be detected (errors that affect only one bit) or multiple errors if odd number of bits are affected

o This setup cannot detect where the error takes place and therefore it cannot be corrected

2.5 Hamming Code:

Motivation

Hamming code enables single errors to be detected and corrected

Description

  • Employs P parity bits for M data bits, where:
  • Parity bits are placed in positions power of 2, between data bits:

P1, P2, P4, P8, P16, …

  • Each parity bit checks those data bits located in positions that, expressed in binary, have ‘1’-s on columns that correspond to that parity bit

Bit position 8 4 2 1 Parity bit 1 0 0 0 1 P 2 0 0 1 0 P 3 0 0 1 1 P1, P 4 0 1 0 0 P 5 0 1 0 1 P1, P 6 0 1 1 0 P2, P 7 0 1 1 1 P1, P2, P 8 1 0 0 0 P 9 1 0 0 1 P1, P 10 1 0 1 0 P2, P

2 ≥ P + M + 1

P

  • Therefore parity bits check the following:

P1 -> P1, D3, D5, D7, D9, …

P2 -> P2, D3, D6, D7, D10, D11, … P4 -> P4, D5, D6, D7, D12, D13, D14, D15, … P8 -> P8, D9, D10, D11, D12, D13, D14, D15, …

Encoding and Transmission

  • Count number of data bits: M
  • Determine number of parity bits P, such as:

2 P ≥ P + M + 1

  • For each of the P parity bits list the data bits checked by it and determine its value based on the values of the data bits and of the even or odd parity used
  • Place the parity bits between data bits in their locations forming a Hamming coded sequence:

P1, P2, D3, P4, D5, D6, D7, P8, D9, D10, D11, …

  • Transmit the Hamming coded sequence of bits

Example

Encoding and Transmission

  • Data bits: 1010
  • Count number of data bits: M = 4
  • Number of parity bits P = 3, such as:
  • Hamming coded sequence:

P1 P2 D3 P4 D5 D6 D 1 0 1 0

C8 C4 C2 C1 Error bit 0 0 0 0 None 0 0 0 1 P 0 0 1 0 P 0 0 1 1 D 0 1 0 0 P 0 1 0 1 D 0 1 1 0 D 0 1 1 1 D 1 0 0 0 P 1 0 0 1 D 1 0 1 0 D

  • Compute the P parity bits based on even parity:

P1 -> P1, D3, D5, D7 <=> P1, 1, 0, 0 => P1 = 1

P2 -> P2, D3, D6, D7 <=> P2, 1, 1, 0 => P2 = 0 P4 -> P4, D5, D6, D7 <=> P4, 0, 1, 0 => P4 = 1

  • Place the parity bits between data bits in their locations forming a Hamming coded sequence:
  • Transmit the Hamming coded sequence of bits

Error Detection and Correction

  • Assume received code: 1001010
  • Length of the Hamming coded sequence N = 7
  • Number of correction bits: P = 3, such as:

2 P = 23 ≥ N + 1 = 8

P1 P2 D3 P4 D5 D6 D 1 0 1 1 0 1 0

P1 P2 D3 P4 D5 D6 D 1 0 0 1 0 1 0