module 1 number systems and code1

20
MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17 Dept. of Computer Science And Applications, SJCET, Palai Page 1 NUMBER SYSTEMS "A set of values used to represent different quantities is known as Number System". For example, a number system can be used to represent the number of students in a class or number of viewers watching a certain TV program etc. The digital computer represents all kinds of data and information in binary numbers. It includes audio, graphics, video, text and numbers. The total number of digits used in a number system is called its base or radix. A 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 base is defined as the total number of digits available in the number system). Efficiency of Number System Number systems provide the basis for all operations in information processing systems. In a number system the information is divided into a group of symbols A group of bits which is used to represent the discrete elements of information is a symbol. The most common are the decimal, binary, octal, and hexadecimal systems. Bits and Bytes • A binary digit is a single numeral in a binary number. • Each 1 and 0 in the number below is a binary digit: 1 0 0 1 0 1 0 1 • The term “binary digit” is commonly called a “bit.” • Eight bits grouped together is called a “byte.” Positional Number Systems We are all familiar with the traditional base-10 number system, which uses 10 digits (0 to 9) and in which the positions increase in value by powers of 10 from right to left. For example, the number 487 is interpreted as 4 hundreds plus 8 tens plus 7 ones. Other number systems work similarly, using different numbers for their bases. In computer science we are particularly interested in binary, octal, and hexadecimal systems, which are base 2, 8, and 16 respectively.

Upload: deepak-john

Post on 09-Jul-2015

217 views

Category:

Education


2 download

DESCRIPTION

Number systems - Efficiency of number system, Decimal, Binary, Octal, Hexadecimalconversion from one to another- Binary addition, subtraction, multiplication and division, representation of signed numbers, addition and subtraction using 2’s complement and I’s complement. Binary codes - BCD code, Excess 3 code, Gray code, Alphanumeric code, Error detection codes, Error correcting code.Deepak john,SJCET-Pala

TRANSCRIPT

Page 1: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 1

NUMBER SYSTEMS

"A set of values used to represent different quantities is known as Number System". For example, a

number system can be used to represent the number of students in a class or number of viewers watching a

certain TV program etc. The digital computer represents all kinds of data and information in binary

numbers. It includes audio, graphics, video, text and numbers. The total number of digits used in a number

system is called its base or radix. A 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 base is defined as the total number of digits available in the

number system).

Efficiency of Number System

Number systems provide the basis for all operations in information processing systems.

In a number system the information is divided into a group of symbols

A group of bits which is used to represent the discrete elements of information is a symbol.

The most common are the decimal, binary, octal, and hexadecimal systems.

Bits and Bytes

• A binary digit is a single numeral in a binary number.

• Each 1 and 0 in the number below is a binary digit:

– 1 0 0 1 0 1 0 1

• The term “binary digit” is commonly called a “bit.”

• Eight bits grouped together is called a “byte.”

Positional Number Systems

We are all familiar with the traditional base-10 number system, which uses 10 digits (0 to 9) and in

which the positions increase in value by powers of 10 from right to left. For example, the number

487 is interpreted as 4 hundreds plus 8 tens plus 7 ones.

Other number systems work similarly, using different numbers for their bases. In computer science

we are particularly interested in binary, octal, and hexadecimal systems, which are base 2, 8, and 16

respectively.

Page 2: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 2

The relationship between these number systems can be seen in the following table, where the zero

position refers to the rightmost digit of a number, and the ^ symbol represents exponentiation:

Position Value in base:

10 2 8 16

0 10^0 = 1 2^0 = 1 8^0 = 1 16^0 = 1

1 10^1 = 10 2^1 = 2 8^1 = 8 16^1 = 16

2 10^2 = 100 2^2 = 4 8^2 = 64 16^2 = 256

3 10^3 = 1000 2^3 = 8 8^3 = 512 16^3 = 4,096

4 10^4 = 10,000 2^4 = 16 8^4 = 4,096 16^4 = 65,536

5 10^5 = 100,000 2^5 = 32 8^5 = 32,768 16^5 = 1,048,576

6 10^6 = 1,000,000 2^6 = 64 8^6 = 262,144 16^6 = 16,777,216

7 10^7 = 10,000,000 2^7 = 128 8^7 = 2,097152 16^7 = 268,435,456

Computer Number Systems

1. Binary Numbers

2. Decimal Numbers

3. Octal Numbers\

4. Hexadecimal Numbers

1. Binary Numbers

Digital computer represents all kinds of data and information in the binary system. Binary Number

System consists of two digits 0 and 1. Its base is 2. Each digit or bit in binary number system can be 0 or 1.

A combination of binary numbers may be used to represent different quantities like 1001. The positional

value of each digit in binary number is twice the place value or face value of the digit of its right side. The

weight of each position is a power of 2.

Numbering of the digits

msb lsb

n-1 0

Where n is the number of digits in the number. (msb stands for most significant bit, lsb stands for least

significant bit).

Example

Page 3: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 3

Binary Number: 101012

2. Decimal Number

The Decimal Number System consists of ten digits from 0 to 9. These digits can be used to represent any

numeric value. The base of decimal number system is 10. It is the most widely used number system. The

value represented by individual digit depends on weight and position of the digit.

The value of the number is determined by multiplying the digits with the weight of their position and

adding the results. This method is known as expansion method. The rightmost digit of number has the

lowest weight. This digit is called Least Significant Digit (LSD). The leftmost digit of a number has the

highest weight. This digit is called Most Significant Digit (MSD). For example, the decimal number 1234

consists of the digit 4 in the units position, 3 in the tens position, 2 in the hundreds position, and 1 in the

thousands position, and its value can be written as

(1x1000)+ (2x100) + (3x10) + (4xl)

(1x103)+ (2x10

2) + (3x10

1) + (4xl0

0)

1000 + 200 + 30 + 4

1234

Decimal to Binary conversion

Step – 1: Divide the decimal number to be converted by the value of the new base. In this case divide it by

2.

Step – 2: Record the remainder from Step – 1 as the rightmost digit.

Step – 3: Divide the quotient of the previous by the new base.

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

Step – 5: Bottom to top sequence of remainder will be the required converted number. Repeat Step – 3 &

Step – 4, recording remainders from right to left, until the quotient becomes less than the digit of new base

so that it cannot be divided.

Ex:

Page 4: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 4

The fractional part is again multiplied by 2 and the process repeated.

Example: convert (0.68)10 to binary fraction.

0.68 * 2 = 1.36 integer part is 1

0.36 * 2 = 0.72 integer part is 0

0.72 * 2 = 1.44 integer part is 1

0.44 * 2 = 0.88 integer part is 0

Answer = 0. 1 0 1 0…..

Example: Convert (0.625)10

0.625 x 2 = 1.25(Product) Fractional part=0.25 Carry=1 (MSB)

0.25 x 2 = 0.50(Product) Fractional part = 0.50 Carry = 0

0.50 x 2 = 1.00(Product) Fractional part = 1.00 Carry = 1 (LSB)

The fractional part in the 3rd iteration becomes zero and hence we stop the multiplication iteration.

Carry from the 1st multiplication iteration becomes MSB and carry from 3rd iteration becomes LSB.

Hence, the fractional binary number of the given fractional decimal number (0.625)10 is (0.101)2.

Binary to Decimal Conversion

• Step 1: Multiply each bit by 2n, where n is the “weight” of the bit

• Step 2: The weight is the position of the bit, starting from 0 on the right

Step 3:Add the results

Ex: Convert the binary number 101012 to decimal.

Step Binary Number Decimal Number

Step 1 101012 ((1 x 24) + (0 x 2

3) + (1 x 2

2) + (0 x 2

1) + (1 x 2

0))10

Step 2 101012 (16 + 0 + 4 + 0 + 1)10

Step 3 101012 2110

1. Convert (101.101)2

↑ ↑

MSB LSB

= 1 x 22 + 0 x 2

1 + 1 x 2

0. 1 x 2

-1 + 0 x 2

-2 + 1 x 2

-3

= 1 x 4 + 0 x 2 + 1 x 1. 1 x ( 1 / 2 ) + 0 x ( 1 / 4 ) + 1 x ( 1 / 8 )

Page 5: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 5

= 4 + 0 + 1 . (1 / 2) + 0 + (1 / 8)

= 5. 0.5 + 0.125

= 5. 625

Therefore (1 0 1. 1 0 1)2 = (5.625)10

3. Convert (0.0001)2

= 0 x 20. 0 x 2

-1 + 0 x 2

-2 + 0 x 2

-3+ 1 x 2

-4

= 0 x 1. 0 x ( 1 / 2 ) + 0 x ( 1 / 4 ) + 0 x ( 1 / 8 ) + 1 x ( 1 / 16 )

= 0. 0 + 0 + 0 + (1 / 16)

= 0. 0.0625

= 0. 0625

Therefore (0. 0 0 0 1)2 = (0.0625)10

4. Convert (101010.1111)2

= 1 x 25 + 0 x 2

4 + 1 x 2

3 + 0 x 2

2 + 1 x 2

1 + 0 x 2

0. 1 x 2

-1 + 1 x 2

-2 + 1 x 2

-3 + 1 x 2

-4

= 1 x 32 + 0 x 16 + 1 x 8 + 0 x 4

+ 1 x 2

+ 0 x 1. 1 x ( 1 / 2 )

+ 1 x ( 1 / 4 ) + 1 x ( 1 / 8 )

+ 1 x ( 1 / 16 )

= 32 + 0 + 8 + 0

+ 2

+ 0 . (1 / 2)

+ ( 1 / 4 ) + ( 1 / 8 )

+ ( 1 / 16 )

= 32 + 8 + 2

. ( 0.5 )

+ ( 0.25 ) + ( 0.125 )

+ ( 0.0625 )

= 42. 9375

Therefore (1 0 1 0 1 0. 1 1 1 1)2 = (42.9375)10

1. Octal Number System

Base or radix 8 number system.

1 octal digit is equivalent to 3 bits.

Octal numbers are 0 to7.

Numbers are expressed as powers of 8.

For example:

Octal to Binary

Converting from octal to binary is as easy as converting from binary to octal. Simply look up each octal

digit to obtain the equivalent group of three binary digits.

Page 6: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 6

Octal: 0 1 2 3 4 5 6 7

Binary: 000 001 010 011 100 101 110 111

Octal to decimal

Example: convert (632)8 to decimal

= (6 x 82) + (3 x 81) + (2 x 80)

= (6 x 64) + (3 x 8) + (2 x 1)

= 384 + 24 + 2

= (410)10

Ex: (407.304)8

= 4 x 8 2 + 0 x 8

1 + 7 x 8

0 . 3 x 8

-1 + 0 x 8

-2 + 4 x 8

-3

= 4 x 8

2 + 0 x 8

1 + 7 x 8

0 . 3 x 8

-1 + 0 x 8

-2 + 4 x 8

-3

= 4 x 64 + 0 x 8

+ 7 x 1

. 3 x ( 1 / 8 ) + 0 x ( 1 / 64 ) + 4 x ( 1 / 512 )

= 256 + 0

+ 7

. (0. 375) + (0) + (0. 0078125)

= (263 . 3828125)10

Decimal to octal

To convert from decimal to octal, the successive-division procedure or the sum of weights procedure

can be used

Ex: Convert (177)10 to octal

177 / 8 = 22 remainder is 1

22 / 8 = 2 remainder is 6

2 / 8 = 0 remainder is 2

Answer = 2 6 1

Binary to octal

group the binary positions in groups of three

Convert the following binary numbers into octal: a) 10110111 b) 01101100

Solution

10110111 = 010 110 111 = 267

01101100 = 001 101 100 = 154

2. Hexa decimal number system

Base or radix 16 number system.

Page 7: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 7

1 hex digit is equivalent to 4 bits.

Numbers are 0, 1, 2…..8, 9, A, B, C, D, E, and F.

B is 11, E is 14.

Numbers are expressed as powers of 16.

Hex to binary

replace each hexadecimal number with four equivalent binary numbers even if the number can be

represented by less than four bits

Convert the following hexadecimal number into binary: a) A2E b)60F

Solution:

a) (A2E)16 = 1010 0010 1110

= (101000101110)2

b) (60F)16 = 0110 0000 1111 = (011000001111)2

Binary to hexadecimal

grouping the binary positions in groups of four

Convert the following binary numbers into hexadecimal: a) 10101111 b) 01101100

Solution:

10110111 = 1011 0111 = (B 7)16

01101100 = 0110 1100 = (6 C)16

Hex to decimal

To convert from hexadecimal to decimal, (multiply by weighting factors).

Convert (7AD) 16 to decimal.

Solution:

(7AD)16 = 7 x 162 + 10 x 16

1 + 13 x 16

0 = (1965)10

Decimal to hex

To convert from decimal to hexadecimal, the successive-division procedure or the sum of weights

procedure can be used.

Convert the following decimal numbers to hexadecimal: a) (596)10 b) (100)10

Solution:

596 ÷ 16 = 37 remainder 4

37 ÷ 16 = 2 remainder 5

2 ÷ 16 = 0 remainder 2

Page 8: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 8

Answer=254

1000 ÷ 16 = 62 remainder 8

62 ÷ 16 = 3 remainder 14

3 ÷ 16 = 0 remainder 3

Answer= 3E8

Conversion Table

Decimal Binary Octal 3-bit String Hexa-decimal 4-bit String

0 0 0 000 0 0000

1 1 1 001 1 0001

2 10 2 010 2 0010

3 11 3 011 3 0011

4 100 4 100 4 0100

5 101 5 101 5 0101

6 110 6 110 6 0110

7 111 7 111 7 0111

8 1000 10 - 8 1000

9 1001 11 - 9 1001

10 1010 12 - A 1010

11 1011 13 - B 1011

12 1100 14 - C 1100

13 1101 15 - D 1101

14 1110 16 - E 1110

15 1111 17 - F 1111

Fig 1.1 Number system conversion

Page 9: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 9

BINARY ADDITION & SUBSTRACTION

Rules for Addition

0 + 0 = 0

0 + 1 = 1

1 + 0 = 1

1 + 1 = 0, and carry 1 to the next more significant bit

For example,

00011010 + 00001100 = 00100110

0 0 0 1 1 0 1 0 = 26(base 10)

+ 0 0 0 0 1 1 0 0

= 12(base 10)

0 0 1 0 0 1 1 0 = 38(base 10)

00010011 + 00111110 = 01010001

0 0 0 1 0 0 1 1 = 19(base 10)

+ 0 0 1 1 1 1 1 0

= 62(base 10)

0 1 0 1 0 0 0 1 = 81(base 10)

The rules of binary addition (without carries) are the same as the truths of the XOR gate.

Rules of Binary Subtraction

0 - 0 = 0

0 - 1 = 1, and borrow 1 from the next more significant bit

1 - 0 = 1

1 - 1 = 0

For example,

00100101 - 00010001 = 00010100

0 0 10 0 1 0 1 = 37(base 10)

- 0 0 0 1 0 0 0 1 = 17(base 10)

Page 10: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 10

BINARY MULTIPLICATION & DIVISION

Rules of Binary Multiplication

0 x 0 = 0

0 x 1 = 0

1 x 0 = 0

1 x 1 = 1, and no carry or borrow bits

For example,

00101001 × 00000110 = 11110110 0 0 1 0 1 0 0 1 = 41(base 10)

× 0 0 0 0 0 1 1 0

= 6(base 10)

0 0 0 0 0 0 0 0

0 0 1 0 1 0 0 1

0 0 1 0 1 0 0 1

0 0 1 1 1 1 0 1 1 0 = 246(base 10)

00010111 × 00000011 = 01000101 0 0 0 1 0 1 1 1 = 23(base 10)

× 0 0 0 0 0 0 1 1

= 3(base 10)

0 0 0 1 0 1 1 1

0 0 0 1 0 1 1 1

0 0 0 1 0 1 0 0 = 20(base 10)

00110011 - 00010110 = 00011101

0 0 1 1 0 0 1 1 = 51(base 10)

- 0 0 0 1 0

1 1 0

= 22(base 10)

0 0 0 1 1

1 0 1 = 29(base 10)

Page 11: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 11

0 0 1 0 0 0 1 0 1 = 69(base 10)

Note: The rules of binary multiplication are the same as the truths of the AND gate.

Another Method: Binary multiplication is the same as repeated binary addition; add the multiplicand to

itself the multiplier number of times.

For example,

00001000 × 00000011 = 00011000

0 0 0 0 1 0 0 0 = 8(base 10)

0 0 0 0 1 0 0 0 = 8(base 10)

+ 0 0 0 0 1 0 0 0

= 8(base 10)

0 0 0 1 1 0 0 0 = 24(base 10)

Binary Division

For example,

Fig 1.2 example for binary division

REPRESENTATION OF SIGNED NUMBERS

There are three basic ways to represent signed numbers:

Sign-magnitude.

1’s complement.

Page 12: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 12

2’s complement.

Sign-Magnitude

The number consists of two parts:

the MSB (most significant bit) represents the sign

The other bits represent the magnitude of the number.

If the sign bit is 1 the number is negative and if it is 0 the number is positive

Examples

I. -30 = 1 0011110 (The leftmost 1 indicates that the number is negative. The remaining 7-bits

carry the magnitude of 30).

II. 30 = 0 0011110 (The only difference between –30 and +30 is the sign bit because the

magnitude bits are similar in both numbers.).

III. -121 = 1 1111001.

IV. 99 = 0 1100011

1’s Complement

Negative numbers are represented in 1’s complement format.

positive numbers are represented as the positive sign-magnitude numbers

Examples

30 = 00011110

-30 = 11100001

the number equals the 1’s complement of 30

121 = 01111001

-121 = 10000110

the number equals the 1’s complement of 121

99 = 01100011

2’s Complement

The two’s complement of a binary integer is the 1’s complement of the number plus 1.”

Thus if m is the 2’s complement of n, then: m = n + 1.

Examples:

n = 0101 0100, then m = 1010 1011 + 1 = 1010 1100

n = 0101 1111, then m = 1010 0000 + 1 = 1010 0001

n = 0111 1111, then m = 1000 0000 + 1 = 1000 0001

n = 0000 0001, then m = 1111 1110 + 1 = 1111 1111

Page 13: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 13

To convert a negative decimal number to 2 To convert a negative decimal number to 2 s’

complement binary: complement binary:

i. Convert the decimal number to a positive binary number.

ii. Take the 1’s complement of that binary number and add 1.

• Ex

– 50: 50 = 0011 0010; 1’s C. = 1100 1101; 2’s C. = 1100 1110.

– 127: 127 = 0111 1111; 1’s C. = 1000 0000; 2’s C. = 1000 0001.

– 1: 1 = 0000 0001; 1’s C. = 1111 1110; 2’s C. =1111 1111

ADDITION AND SUBTRACTION USING 2’S AND I’S COMPLEMENT

1’s and 2’s complement allow the Representation of Negative numbers (-) in binary.

1's complement

The 1's complement of a binary number is found by simply changing all 1s to 0s and all 0s to 1s.

Examples

The 1’s complement of 10001111 = 01110000.

The 1’s complement of 01101100 = 10010011.

The 1’s complement of 00110011 = 11001100.

2's complement

The 2's complement of a binary number is found by adding 1 to the LSB of the 1’s complement.

Another way of obtaining the 2’s complement of a binary number is to start with the LSB (the

rightmost bit) and leave the bits unchanged until you find the first 1. Leave the first 1 unchanged

and complement the rest of the bits (change 0 to 1 and 1 to 0).

Example

The 2’s complement of 10001111 = 01110000 +1 = 01110001

The 2’s complement of 01101100 = 10010011 + 1 =10010100

The 2’s complement of 00110011 = 11001100 + 1 = 11001101

Addition of 2’s complement binary numbers

Subtraction

There are two possibilities

a) M>=N

b) M<N

Page 14: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 14

If M>=N then follow the given steps

Steps

1: Add the minuend M to the r’s complement of the subtrahend N

2: inspect the result obtained in step 1 for an end carry

a) If an end carry occurs discard it.

b) If an end carry doesn’t occur, take the r’s complement of the number obtained in step 1

and place a negative sign in front.

If M<N then follow the above steps with given additional steps

3. Answer is obtained by taking a r’s compliment of obtained sum and adding a negative sign

Subtraction using 1's complement

The method of binary subtraction becomes very easy with the help of 1's complement. Now let us look at

an example to understand subtraction using 1's complement. –

Suppose A = (0 1 0 1)2

And B = (0 0 1 1)2

And we want to find out A - B

For this first we have to calculate 1's complement of B

1's complement of B = 1 1 0 0

Now we have to add the result with A

Now in the result we can see that there is an overflowing bit which we have to add with the remaining

result

This is the desired result. And when there will not be any overflowing digit the result obtained in the

previous stage will be the answer.

Subtraction using 2’s complement

Page 15: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 15

One of the most popular applications of 2's complement is the subtraction of binary numbers using 2's

complement method. This method is preferred because here subtraction can be done by doing additions.

With an example we will be able to grasp the method at once.

We want to do 7 - 12

Step1

Taking 2's complement of minuend (12) which is = 1 1 1 1 0 1 0 0

Step 2

Adding the result with binary equivalent of 7

So the subtraction method using 2's complement method is hereby explained.

Binary codes

• Digital data is represented, stored and transmitted as group of binary bits.

• This group is called binary code.

• The binary code can be used for represent the number as well as alphanumeric letters.

1. Weighted Binary Systems- Weighted binary codes are those which obey the positional weighting

principles, each position of the number represents a specific weight.

2. Non Weighted Codes- Non weighted codes are codes that are not positionally weighted. That is,

each position within the binary number is not assigned a fixed value.

Binary Coded Decimal (BCD)

Represent each decimal digit as a 4-bit binary code.

Binary-Coded Decimal is a weighted code because each decimal digit can be obtained from its code

word by assigning a fixed weight to each code-word bit.

The weights for the BCD bits are 8, 4, 2, and 1, and for this reason the code is sometimes called the

8421 code.

Examples:

(234)10 = (0010 0011 0100)BCD

(7093)10 = (0111 0000 1001 0011)BCD

(1000 0)BCD = (86)10

(1001 (1001 0100 0111 0010)BCD = (9472)10

Notes: BCD is not equivalent to binary.

Page 16: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 16

Example: (234)10 = (11101010)2

GRAY Code

• It is called cyclic or reflected code.

• In this code each code group does not differ from its neighbor in more than one bit.

• This code is used for input and output devices in digital system.

Decimal Binary Gray Code Decimal Binary Gray code

0 0000 0000 8 1000 1100

1 0001 0001 9 1001 1101

2 0010 0011 10 1010 1111

3 0011 0010 11 1011 1110

4 0100 0110 12 1100 1010

5 0101 0111 13 1101 1011

6 0110 0101 14 1110 1001

7 0111 0100 15 1111 1000

Fig 1.2 GRAY code system

Binary into Gary Code

The following Method can be used

1. Write down binary form of the given decimal number.

2. Write MSB as such.

3. Then XOR the binary digit from left to right at the adjacent position.

4. Discard carry if any.

5. Write the digit which comes after addition.

Fig 1.3 binary –gray conversion

Gray – binary

• Method:

1. Write the given grey code.

2. Write the MSB bit as such.

3. XOR this bit to the second left most bit, write the result, and discard carry.

4. Add this result to the next left most bit diagonally.

Page 17: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 17

Fig 1.4 Gray –Binary conversion

Excess -3 Code

This counting system starts from a count of binary three (0011) then counts up.

Fig 1.5 excess 3 code

Alphanumeric Codes

Apart from numbers, computers also handle textual data.

Character set frequently used includes:

alphabets: ‘A’ .. ‘Z’, and ‘a’ .. ‘z’

digits: ‘0’ .. ‘9’

special symbols: ‘$’, ‘.’, ‘,’, ‘@’, ‘*’, …

Alphanumeric codes are codes used to encode the characters of alphabets in addition to the decimal

digits. They are used primarily for transmitting data between computers and its I/O devices.

Usually, these characters can be represented using 7 or 8 bits.

ASCII

The most commonly used character code is ASCII (the American Standard Code for Information

Interchange).

ASCII represents each character with a 7-bit string, yielding a total of 128 characters.

Page 18: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 18

The code contains the uppercase and lower case alphabet, numeral, punctuation, and various

nonprinting control characters.

7-bit, plus a parity bit for error detection (odd/even parity).

Character ASCII Code

0 0110000

1 0110001

. . . . . .

9 0111001

: 0111010

A 1000001

B 1000010

. . . . . .

Z 1011010

[ 1011011

\ 1011100

Fig 1.6 ASCII code example

EBCDIC

Extended Binary Coded Decimal Interchange Code (EBCDIC) is an 8-bit character encoding.

Error Detection Codes

Errors can occur data transmission. They should be detected, so that re-transmission can be

requested. With binary numbers, usually single-bit errors occur.

Example: 0010 erroneously transmitted as 0011, or 0000, or 0110, or 1010.

Error-detecting codes normally add extra information to the data. In general, error-detecting codes

contains redundant code. That is a code that uses n-bit strings need not contain 2n valid code words.

An error-detecting code has the property that corrupting or garbling a code word will likely produce

a bit string that is not a code word. Thus errors in a bit string can be detected by a simple rule - if it

is not a code word it contains an error.

Commonly used error detecting codes area.

a. parity code

b. Checksums

c. Block Parity

a. Parity bit.

Page 19: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 19

Even parity: additional bit supplied to make total number of ‘1’s even.

Odd parity: additional bit supplied to make total number of ‘1’s odd.

Fig 1.7 Parity Check

Error correcting Code

Hamming code is a set of error-correction code s that can be used to detect and correct bit errors

that can occur when computer data is moved or stored.

The key to the Hamming Code is the use of extra parity bits to allow the identification of a single

error. Create the code word as follows:

1. Mark all bit positions that are powers of two as parity bits. (Positions 1, 2, 4, 8, 16, 32, 64, etc.)

2. All other bit positions are for the data to be encoded. (Positions 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15,

17, etc.)

3. Each parity bit calculates the parity for some of the bits in the code word. The position of the parity

bit determines the sequence of bits that it alternately checks and skips.

Position 1: check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, etc. (1,3,5,7,9,11,13,15,...)

Position 2: check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, etc. (2,3,6,7,10,11,14,15,...)

Position 4: check 4 bits, skip 4 bits, check 4 bits, skip 4 bits, etc.

(4,5,6,7,12,13,14,15,20,21,22,23,...)

Position 8: check 8 bits, skip 8 bits, check 8 bits, skip 8 bits, etc. (8-15,24-31,40-47,...)

Position 16: check 16 bits, skip 16 bits, check 16 bits, skip 16 bits, etc. (16-31,48-63,80-95,...)

Position 32: check 32 bits, skip 32 bits, check 32 bits, skip 32 bits, etc. (32-63,96-127,160-191,...)

etc.

4. Set a parity bit to 1 if the total number of ones in the positions it checks is odd. Set a parity bit to 0

if the total number of ones in the positions it checks is even.

Page 20: Module 1  number systems and code1

MODULE 1 MCA-102 DIGITAL SYSTEMS & LOGIC DESIGN ADMN 2014-‘17

Dept. of Computer Science And Applications, SJCET, Palai Page 20

Here is an example:

A byte of data: 10011010

Create the data word, leaving spaces for the parity bits: _ _ 1 _ 0 0 1 _ 1 0 1 0

Calculate the parity for each parity bit (a ? represents the bit position being set):

Position 1 checks bits 1, 3, 5, 7, 9, 11:

? _ 1 _ 0 0 1 _ 1 0 1 0. Even parity so set position 1 to a 0: 0 _ 1 _ 0 0 1 _ 1 0 1 0

Position 2 checks bits 2, 3, 6, 7, 10, 11:

0 ? 1 _ 0 0 1 _ 1 0 1 0. Odd parity so set position 2 to a 1: 0 1 1 _ 0 0 1 _ 1 0 1 0

Position 4 checks bits 4, 5, 6, 7, 12:

0 1 1 ? 0 0 1 _ 1 0 1 0. Odd parity so set position 4 to a 1: 0 1 1 1 0 0 1 _ 1 0 1 0

Position 8 checks bits 8, 9, 10, 11, 12:

0 1 1 1 0 0 1 ? 1 0 1 0. Even parity so set position 8 to a 0: 0 1 1 1 0 0 1 0 1 0 1 0

Code word: 011100101010.

Finding and fixing a bad bit

The above example created a code word of 011100101010. Suppose the word that was

received was 011100101110 instead. Then the receiver could calculate which bit was wrong and

correct it. The method is to verify each check bit. Write down all the incorrect parity bits. Doing so,

you will discover that parity bits 2 and 8 are incorrect. It is not an accident that 2 + 8 = 10, and that

bit position 10 is the location of the bad bit. In general, check each parity bit, and add the positions

that are wrong, this will give you the location of the bad bit.