Docsity

Binary Codes, Study notes of Electronics

Partial preview of the text

Download Binary Codes and more Study notes Electronics in PDF only on Docsity!

Binary Codes

Computer Mathematics I

Jiraporn Pooksook Department of Electrical and Computer Engineering Naresuan University

BINARY CODES: BCD

Figure: Retrieved from https://www.electronics- tutorials.ws/binary/binary-coded-decimal.html

BINARY CODES: BCD

Binary Coded Decimal system is represented by a group of 4 bits using binary notation from 0000 to 1001. Binary coded decimal is different from hexadecimal because BCD numbers stop at 9 binary 1001 2. The advantage of BCD is that it allows easy conversion between decimal (base-10) and binary (base-2) form. However, the disadvantage is that BCD code is wasteful.

Example: 12 to BCD=? 00012 = 1 00102 = 2 Then, = 0001 0010

Example: 92 to BCD=? 10012 = 9 00102 = 2 Then, = 1001 0010

BINARY CODES: EXCESS-

This is an unweighted code. It is obtained from the value of BCD adding by 3.

Example: 12 to Excess-3=? 01002 = 1 01012 = 2 Then, = 0100 0101

Example: 92 to Excess-3=? 11002 = 9 01012 = 2 Then, = 1100 0101

BINARY CODES: 2421

This is also a weighted code similarly to BCD.

Example: 12 to 2421=? 0001 = 1 0010 = 2 Then, = 0001 0010

Example: 92 to 2421=? 1111 = 9 0010 = 2 Then, = 1111 0010

SELF-COMPLEMENTING

The excess-3, 84-2-1, and 2421 codes are examples of self-complementing codes. Example : Excess- 395 = 0110 1100 1000 604 = 1001 0011 0111 (The 9’s complement of each number)

Figure: Retrieved from Digital Design / M. Morris R. Mano, Micheal D. Ciletti.-3nd ed.

GRAY CODE

Converting Binary to Gray:

  1. The most significant bit of the gray number is the most significant bit of the binary code
  2. Add the next significant bit of the binary number to the next significant bit of the binary number to obtain the next gray coded bit
  3. Repeat until all bits are changed. Example: Binary = 0000 Gray = 0000 Binary = 0001 Gray = 0001 Binary = 0010 Gray = 0011 Binary = 0011 Gray = 0010 Binary = 0100 Gray = 0110

CONSTRUCT N-BIT GRAY CODE

n-bit code can be generated by n-1 bit code. Example(from 2 bits to 3 bits): Adding prefix 0 to the gray code in 2 bits Gray = 00 ⇒ 000 Gray = 01 ⇒ 001 Gray = 11 ⇒ 011 Gray = 10 ⇒ 010 Then adding prefix 1 to the reflects Gray = 10 ⇒ 110 Gray = 11 ⇒ 111 Gray = 01 ⇒ 101 Gray = 00 ⇒ 100 This method is the cyclic code.

ERROR DETECTING CODE: BIT PARITY

ERROR DETECTING CODE: BIT PARITY

The parity bit’s task: I (^) If an even parity bit is generated in the sending end for each message transmission, the message together with the parity bit is transmitted to its destination. I (^) The parity of the received data is checked. If the parity of the received information is not even, it means that at least one bit has changed value during the transmission. I (^) After an error is detected, there are many solution depending on the situation. One possibility is to request retransmission.

EVEN-PARITY BCD

I (^) If the number of 1’s is odd, then P = 1. I (^) If the number of 1’s is even, then P = 0. Example: 0100 1 , 0110 0 What if the data 01010 is changed to 01011 Detectable? 11010 Detectable? 11111 Detectable? 00110 Detectable? Problem: Can’t detect which bit is in error. Can’t detect even numbers of errors.

ERROR-DETECTING CODE: BIT PARITY

Minimum distance of a code = smallest no. of bits in which any two codewords differ Example: Message 1 = 01101 Message 2 = 10011 Message 3 = 00110 Message 4 = 11000 Distance between codes: Message 1 and Message 2 = 4 Message 1 and Message 3 = 3 Hence, the minimum distance of a code = 3.

ERROR-DETECTING CODE: 2 OUT OF 5 CODE

A two-out-of-five code is an m of n code that provides exactly ten possible combinations. It uses five bits representation. There are ways to assign weights to each bit such that the set bits sum to the desired value, with an exception for zero. A two-out-of-five code can have the number of 1’s = 2. Decimal 01247 0 00011 1 11000 2 10100 3 01100 4 10010 5 01010 6 00110 7 10001 8 01001 9 00101

ERROR-DETECTING CODE: 2 OUT OF 5 CODE

If the number of 1’s 6 = 2 and the number of 0’s 6 = 3, detects as errors. What is the minimum distance of 2-out-of-5 code? What if the data 01010 is changed to 01011 Detectable? 11010 Detectable? 01001 Detectable? 00110 Detectable?