Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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)

112 documents

1 / 22

Toggle sidebar

Related documents


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 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 Example • 2 5 9 • 0010 0101 1001 Decimal to BCD Encoder • 10 inputs and 4 outputs • Homework: Implement the encoder using gates S0 S1 S2 S3 S4 S5 S6 S7 S8 S9 B0 B1 B2 B3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 S0 Enc S1 S9 B0 B3 Docsity.com 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’ <=> 9710 = 11000012 = 6116 Decimal 9 7 Binary 0 1 1 0 0 0 0 1 Hexadecimal 6 1 Docsity.com DOS WIN Dec Hex DOS WIN Dec Hex DOS WIN Dec Hex DOS WIN Dec Hex ¢ ¢€ 128 80 4 140 AO |b A 192 CO a a 224 «EO i 129 81) sf i 161 Al JL A 193 Cl |B 4 225 El é , 130 82 |6 ¢ 162 A2 |p A 194 C2 [P & 226 E2 af 13183) fa o£ 163 AS JRO OA 95 C3 fe 2B A * 132 84 |i 4 64 Ad |- A 196 C4 [EO a 228 Ed a 133 85 |N ¥ 6s AS |f A 197 CS |e & 229 ES a 134 86 OF ' 166 A6 |f A 198 C6 |p w 230 B6 ¢ t 135 87 § 167 AT {fF 199 7st § 231 EF a 136 88 |, ” tos As |E EE 200 cs jm @ 232 ES & % 137 89 fF © 169 AD |p E 201 C9 [@ €é& 233° EO e § 138 8A fo 3 170 AA f& E 202 CA |@ & 234 EA i ¢ 139 8B lH I7l AB ff E 203 CB [8 & 235 EB i EG mo 8c fe = 172 ac |F ft 204 OC foo i 236 EC i 41 sD fj . 13 AD f= i 208 CD jo i 237 «ED A #& 142 8B |J« @ IM AE fi 206 CE je i 238 EE A 143° SF > 7 175 AF | ff 207 CF |n i 239 ~EF E 144 90 [Be 17% BO |L p 208 DO é 240 FO e ¢ 145 91 [BO 4 177 Bl |e N 209 DL fe a 241 ‘Fil za 146 92 |B? 178 B2 |r O 210 D2 [> 8 242 F2 6 “ 14793 | 3 179 Bs jk G 211 D3 |e 6 243 F3 6 7 148 94 ‘ 180 B4 |E GO 212 D4 |[ 6 244 F4 o : 149 95) im 181 BS |p 6 213 DS |] 6 245 FS a - 150 9% Ho 4 18 B6 |p OG 214 D6 [+ 6 246 F6 i — 151 97) by 183 BF jf »* 215 DF |= : 247 FT yo 152 98 5 : 1344 BS jf @ 216 Ds | o 248 Fs oO ™ 153 99 We! is Bo [JU 217 De |» a 249 FO uo 8 154 9A |? 186 BA |p U 218 DA a 250 FA ¢ > 155 9B yo» 137 BB IF © 219 DB ly a 251 FB £ o@ is6 9¢ A w% iss Bo M™ OG 20 DC fb i =. 252, FC ¥ is? 9D HW % 18 BD Y 221 DD P y 253 FD Ps iss 96 4 % 199 BE |f Pb 222 DE jm p 254 FE fo ¥ 159 OF Og 191 BF |g 8B 223 DF yj 255 FF Docsity.com 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 Docsity.com Implementation: B0 G0 B1 B2 B3 B4 G1 G2 G3 G4 Binary Number Gray Code B0 B1 B2 B3 G0 G1 G2 G3 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 Docsity.com 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 • 1 1 1 0 1 ↓ ↓ ↓ ↓ ↓ ↓ ⊕ ⊕ ⊕ ⊕ ↓  ↓  ↓  ↓  ↓ • 1 0 1 1 0 Rules: B0 = G0; BN = BN-1 ⊕ GN G0 B0 G1 G2 G3 G4 B1 B2 B3 B4 Docsity.com 2.4 Parity Codes: Motivation When transmitting or storing data, errors can occur and it is highly significant to be able to detect them Definition Parity codes are binary sequences resulted from the original sequence of bits (data in binary representation) after the addition of a single parity bit Types • Even Parity The even parity bit is chosen such as the total number of ‘1’ bits in the sequence is even e.g.:  • Odd Parity The parity bit is such set that the total number of bits equal to ‘1’ in the sequence is odd e.g.: 1 0 1 1 1 0 1 1 1 0 1 0 1 0 0 0 Even parity bit Odd parity bit Docsity.com • Error Correction: o Using a matrix-like setup that makes use of two sets of parity bits: on each word and on corresponding bits from the run of words respectively can detect and correct singular errors H Parity S0 S1 S2 S3 S4 S5 S6 S7 Value 0 0 1 0 0 0 0 0 1 ‘A’ 0 0 1 0 0 0 0 1 0 ‘B’ 1 0 1 0 0 0 0 1 1 ‘C’ 0 0 1 0 0 0 1 0 0 ‘D’ 1 0 1 0 0 0 1 0 1 ‘E’ 1 0 1 0 0 0 1 1 0 ‘F’ 0 0 1 0 0 0 1 1 1 ‘G’ 0 0 1 0 0 1 0 0 0 ‘H’ 1 0 0 0 0 1 0 0 0 V Parity Note: Even parity was used Docsity.com 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 P1 2 0 0 1 0 P2 3 0 0 1 1 P1, P2 4 0 1 0 0 P4 5 0 1 0 1 P1, P4 6 0 1 1 0 P2, P4 7 0 1 1 1 P1, P2, P4 8 1 0 0 0 P8 9 1 0 0 1 P1, P8 10 1 0 1 0 P2, P8 12 ++≥ MPP Docsity.com • 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: 12 ++≥ MPP • 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 Docsity.com • 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: 8122 3 =+≥= NP P1 P2 D3 P4 D5 D6 D7 1 0 1 1 0 1 0 P1 P2 D3 P4 D5 D6 D7 1 0 0 1 0 1 0 Docsity.com • Compute the value of the correction bits taking into account the even parity used: C1 -> P1, D3, D5, D7 <=> 1, 0, 0, 0 => C1 = 1 C2 -> P2, D3, D6, D7 <=> 0, 0, 1, 0 => C2 = 1 C4 -> P4, D5, D6, D7 <=> 1, 0, 1, 0 => C4 = 0 • Computes the detection code: C4 C2 C1 <=> 0 1 1 2 = 3 10 => Error bit D3 • Perform the correction by inverting the value of the error bit D3 = 1 • Extract the original data: D3 D5 D6 D7 <=> 1 0 1 0 Docsity.com Implementation P1 P2 D3 P4 D5 D6 D7 C1 C2 C4 Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved