Binary Codes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

BINARY CODES

Objectives
To be able to understand the following:
Digital Number System
Binary Number System and Operations
Binary Codes
Errors and Error Connectors
Repetition & Hamming Codes
Digital Number System

When we type some letters or words, the computer


translates them in numbers as computers can understand
only numbers.
 A computer can understand the positional number system
where there are only a few symbols called digits and these
symbols represent different values depending on the
position they occupy in the number.
Digital Number System

The value of each digit in a number can be


determined using −
The digit
The position of the digit in the number
The base of the number system (where the base is
defined as the total number of digits available in
the number system)
Digital Number System

-As a computer programmer or an IT professional, you should


understand the following number systems which are frequently used
in S.No.
computers.
Number System and Description
Decimal Number System
1  The number system that we use in our day-to-day life is the decimal number system.
 has base 10 as it uses 10 digits from 0 to 9

Binary Number System


2
Base 2. Digits used : 0, 1
Octal Number System
3
Base 8. Digits used : 0 to 7
Hexa Decimal Number System
4
Base 16. Digits used: 0 to 9, Letters used : A- F
Binary Number System

Characteristics
◦ Uses two digits, 0 and 1.
◦ Also called base 2 number system
◦ Each position in a binary number represents a 0 power of the
base 2.
◦ Last position in a binary number represents an x power of the
base 2. Example: 2x where x represents the last position - 1.
Example:
1101102 , 11001102, 000000000012
Decimal to Other Base System

Step 1 − Divide the decimal number to be converted by the value of the new base.

Step 2 − Get the remainder from Step 1 as the rightmost digit (least significant digit) of the new base
number.

Step 3 − Divide the quotient of the previous divide by the new base.

Step 4 − Record the remainder from Step 3 as the next digit (to the left) of the new base number.

Repeat Steps 3 and 4, getting remainders from right to left, until the quotient becomes zero in Step 3.
Decimal to Binary
Example
Decimal Number: 2910
Calculating Binary Equivalent −

Step Operation Result Remainder


Step 1 29 / 2 14 1
Step 2 14 / 2 7 0
Step 3 7/2 3 1
Step 4 3/2 1 1
Step 5 1/2 0 1
Answer: 111012
Decimal to Binary
EXERCISE 2: Convert the following Decimal to Binary

110111

Decimal Binary

32 100000
15 1111
40 101000
Decimal to Binary

Step 1 − Determine the column positional value of each


digit

Step 2 − Multiply the obtained column values in Step1 by


the digits in the corresponding columns.

Step 3 − Sum the products calculated in Step 2. The total


is the equivalent value in decimal.
Decimal to Binary
Example
Binary Number: 111012
Calculating Decimal Equivalent −

Step Binary Number Decimal Number


Step 1 111012 ((1x24)+ (1x23)+ (1x22)+ (0x21)+ (1x20))10
Step 2 111012 ((16)+ (8)+ (4)+ (0)+ (1))10
Step 3 111012 2910

Answer: 2910
Binary to Decimal
EXERCISE 1: Convert the following Binary to Decimal

110111

Binary Decimal

000110 6
110111 55
1111101 125
Binary Addition

It is a key for binary subtraction, multiplication, division.


There are four rules of binary addition.
Example − Addition
Binary Addition
EXERCISE 3: Add and compute the sum of the following Binary Numbers

110111

Binary Sum
000111 + 000100 001011
11111 + 10111 110110
101010+100011 1001101
BINARY CODES

In the coding, when numbers, letters or words are represented by a


specific group of symbols, it is said that the number, letter or word is
being encoded.
The group of symbols is called as a code.
The digital data is represented, stored and transmitted as group of
binary bits. This group is also called as binary code.
The binary code is represented by the number as well as
alphanumeric letter.
BINARY CODES
Advantages of Binary Code

Following is the list of advantages that binary code offers.

Binary codes are suitable for the computer applications.

Binary codes are suitable for the digital communications.

Binary codes make the analysis and designing of digital circuits if we use the binary codes.

Since only 0 & 1 are being used, implementation becomes easy.


BINARY CODES
Classification of binary codes

Weighted Non-Weighted Binary Coded


Codes Codes Decimal Code

Error Error
Alphanumeric
Detecting Correcting
Codes
Codes Codes
BINARY CODES

Weighted binary codes are those binary codes


Weighted which obey the positional weight principle. Each
position of the number represents a specific weight.
Codes Several systems of the codes are used to express the
decimal digits 0 through 9. In these codes each
decimal digit is represented by a group of four bits.
BINARY CODES

In this type of binary codes, the positional weights


are not assigned. The examples of non-weighted
Non-Weighted codes are Excess-3 code and Gray code.
Codes Excess-3 code
The Excess-3 code is also called as XS-3 code. It is
non-weighted code used to express decimal
numbers. The Excess-3 code words are derived from
the 8421 BCD code words adding (0011)2 or (3)10 to
each code word in 8421. The excess-3 codes are
obtained as follows −
BINARY CODES
Example

Non-Weighted
Codes
BINARY CODES

In this code each decimal digit is represented by a


Binary Coded 4-bit binary number. BCD is a way to express each of
the decimal digits with a binary code. In the BCD,
Decimal with four bits we can represent sixteen numbers
(0000 to 1111). But in BCD code only first ten of
these are used (0000 to 1001). The remaining six
code combinations i.e. 1010 to 1111 are invalid in
BCD.
BINARY CODES

Advantages of BCD Codes


Binary Coded It is very similar to decimal system.
Decimal We need to remember binary equivalent of decimal numbers
0 to 9 only.
Disadvantages of BCD Codes
The addition and subtraction of BCD have different rules.
The BCD arithmetic is little more complicated.
BCD needs more number of bits than binary to represent the
decimal number. So BCD is less efficient than binary.
BINARY CODES

These symbols are required to


Alphanumeric represent 26 alphabets with capital
Codes and small letters, numbers from 0 to 9,
punctuation marks and other symbols.
codes that represent numbers and
alphabetic characters. Mostly such
codes also represent other characters
such as symbol and various
instructions necessary for c
BINARY CODES

The following three alphanumeric codes are very


commonly used for the data representation.
Alphanumeric American Standard Code for Information Interchange
Codes (ASCII).
Extended Binary Coded Decimal Interchange Code
(EBCDIC).
Five bit Baudot Code
 ASCII code is more commonly used worldwide
while EBCDIC is used primarily in large IBM
computers.
BINARY CODES

Error Codes
Error There are binary code techniques available to detect
Detecting and correct data during data transmission.
Codes What is Error?
Error is a condition when the output information
does not match with the input information. During
transmission, digital signals suffer from noise that
can introduce errors in the binary bits travelling
from one system to other. That means a 0 bit may
change to 1 or a 1 bit may change to 0.
BINARY CODES

Whenever a message is transmitted, it may


Error get scrambled by noise or data may get
Detecting corrupted. To avoid this, we use error-
Codes detecting codes which are additional data
added to a given digital message to help us
detect if an error occurred during
transmission of the message. A simple
example of error-detecting code is parity
check.
BINARY CODES

Along with error-detecting code, we can also pass


Error some data to figure out the original message from
the corrupt message that we received. This type of
Correcting code is called an error-correcting code. Error-
Codes correcting codes also deploy the same strategy as
error-detecting codes but additionally, such codes
also detect the exact location of the corrupt bit.
In error-correcting codes, parity check has a simple
way to detect errors along with a sophisticated
mechanism to determine the corrupt bit location.
Once the corrupt bit is located, its value is reverted
(from 0 to 1 or 1 to 0) to get the original message.
How to Detect and Correct Errors?

To detect and correct the errors, additional bits


are added to the data bits at the time of
transmission.
The additional bits are called parity bits. They allow
detection or correction of the errors.
The data bits along with the parity bits form a code word.
Parity Checking of Error Detection

It is the simplest technique for detecting and correcting


errors. The MSB (Most Significant Bit) of an 8-bits word is
used as the parity bit and the remaining 7 bits are used as
data or message bits. The parity of 8-bits transmitted word
can be either even parity or odd parity.
Even parity -- Even parity means the number of
1's in the given word including the parity bit
should be even (2,4,6,....).
Odd parity -- Odd parity means the number of
1's in the given word including the parity bit
should be odd (1,3,5,....).
Parity Checking of Error Detection
Use of Parity Bit
The parity bit can be set to 0 and 1
depending on the type of the parity
required.
For even parity, this bit is set to 1 or 0
such that the no. of "1 bits" in the entire
word is even. Shown in fig. (a).
For odd parity, this bit is set to 1 or 0
such that the no. of "1 bits" in the entire
word is odd. Shown in fig. (b).
Error detecting Code Example
Error Detection/correction coding:

Word: With even parity:

With Error: Identifying error:


HAMMING CODES

Use for Detecting and Correcting Errors


It can be applied to data units for any length
It is used to detect and correct single bit errors
Structure:
◦ All bit positions that are power of 2 are marked as parity bits (1,2,4,8 ….) other bits are for data

The commonly used structure is the 7 bit hamming code structure


D7 D6 D5 P4 D3 P2 P1
HAMMING CODES

Determining the value of the parity Bits


◦ Rule
◦ The value of parity bit is determined by the sequence of bits that is alternatively checks and Skip
◦ Example:

SENDER 1101 RECEIVER

D7 D6 D5 P4 D3 P2 P1
1 1 0 ? 1 ? ?
HAMMING CODES
Determining the value of the parity Bits cont..
D7 D6 D5 P4 D3 P2 P1
1 1 0 ? 1 ? ?
Find P1:
= Check 1 bit skip 1 bit, check 1 bit skip 1 bit . . . . . . . .
P1 = D3 D5 D7
Find P2:
= Check 2 bit skip 2 bit, check 2 bit skip 2 bit . . . . . . . .
P2 = D3 D6 D7
Find P4:
= Check 4 bit skip 4 bit, check 4 bit skip 4 bit . . . . . . . .
P4 = D5 D6 D7
HAMMING CODES
Determining the value of the parity Bits cont..
D7 D6 D5 P4 D3 P2 P1
1 1 0 ? 1 ? ?
Find P1:
= Check 1 bit skip 1 bit, check 1 bit skip 1 bit . . . . . . . .
P1 = D3 D5 D7
Find P2:
= Check 2 bit skip 2 bit, check 2 bit skip 2 bit . . . . . . . . Parity P1 P2 P4
P2 = D3 D6 D7 101 111 011
Find P4: Parity Check (Even 0 1 0
Parity)
= Check 4 bit skip 4 bit, check 4 bit skip 4 bit . . . . . . . .
P4 = D5 D6 D7
HAMMING CODES
Determining the value of the parity Bits cont..

Apply the Even parity to 7bit hamming code structure


D7 D6 D5 P4 D3 P2 P1
1 1 0 0 1 1 0
HAMMING CODES Detecting Errors
Determining the value of the parity Bits cont..
- Consider a 7 bit HCI (Hamming Code Instruction) - If it is an odd (1) error Exist , If it is even
- Consider the transmission : 1100110 (0) no error
- Solution: - After finding the error word, we finds its
o P1 = P1 D3 D5 D7 = 0101 = 0 decimal value
o P2 = P2 D3 D6 D7 = 1111 = 0  In this example there is no error
o P4 = P4 D5 D6 D7 = 0011 = 0 occurred during the transmission
- Decimal value will identify what bit
- An Error is located by Forming a 3 bit number the error occurred
number out of 3 parity bits (P1, P2,P4) - If error Occurred Invert the incorrect bit
to obtain the correct word
P4 P2 P1
0 0 0
References
Ascii Text to Binary Converter : www.binaryhexconverter.com
Number System Conversion: www.tutorialspoint.com
Digital Number System
https://www.tutorialspoint.com/computer_logical_organization/digital_number_system.htm
Hamming Code Error Detection and Correction Visualization
https://www.youtube.com/watch?v=LiGiU7zrLnU
Information Theory part 14: Error correction codes (Hamming coding)
https://www.youtube.com/watch?v=cBBTWcHkVVY
Hamming Code | Error detection: https://www.youtube.com/watch?v=1A_NcXxdoCc&t=390s
End.
Thank You

You might also like