33
1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 10101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 101010101010101010101010101010101010101010101010101010101010101001010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 1010101010101010101010101010101010101010101010101010101010101010101010101010101010 Contents: Number System. Number Base Conversions. Complements. Subtraction with complements. Binary Codes: Decimal Codes, Reflected Code, Error detection code, Alphanumeric Code Binary Systems and Codes Prepared By Mohammed Abdul kader Assistant Professor, EEE, IIUC

Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

10101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

101010101010101010101010101010101010101010101010101010101010101001010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010

Contents:

Number System.

Number Base Conversions.

Complements.

Subtraction with complements.

Binary Codes: Decimal Codes, Reflected Code, Error detection code, Alphanumeric Code

Binary Systems and Codes

Prepared By

Mohammed Abdul kader

Assistant Professor, EEE, IIUC

Page 2: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

Number System 101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

In general, in any number system there is an ordered set of symbols known as digits with

rules defined for performing arithmetic operations like addition, multiplication etc. A collection of these

digits makes a number in general has two parts- integer and fractional. Set apart by a radix point (.), i.e.

(𝑁)𝑟= 𝑎𝑛−1𝑎𝑛−2 ……𝑎2𝑎1𝑎𝑜 . 𝑎−1𝑎−2 … . 𝑎−𝑚

Integer portion Radix point Fractional portion

where N= a number

r = radix or base of number system

n= number of digits in integer portion

m= number of digits in fractional portion

𝑎𝑛−1 = most significant digit (MSD)

𝑎−𝑚 = least significant digit (LSD)

2

In general, a number expressed in base-r system has coefficients multiplied by powers of r:

𝑎𝑛−1. 𝑟𝑛−1 + 𝑎𝑛−2 . 𝑟𝑛−2 + ⋯+ 𝑎1. 𝑟

1 + 𝑎𝑜. 𝑟0 + 𝑎−1. 𝑟

−1+𝑎−2. 𝑟−2 + ⋯+ 𝑎−𝑚. 𝑟−𝑚

For example, (3456.54)10 can be written as-

3 × 103 + 4 × 102 + 5 × 101 + 6 × 100 + 5 × 10−1 +4 × 10−2

Page 3: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Decimal

(Base 10) Binary

(Base 2) Octal

(Base 8) Hexadecimal

(Base 16)

00 0000 00 0 01 0001 01 1 02 0010 02 2 03 0011 03 3 04 0100 04 4 05 0101 05 5 06 0110 06 6 07 0111 07 7 08 1000 10 8 09 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F

Numbers with different Base

3

Page 4: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary to Decimal:

Convert binary 1010.011 2 into decimal.

1010.011 2 = 1 × 23 + 0 × 22 + 1 × 21 + 0 × 20 + 0 × 2−1 + 1 × 2−2 + 1 × 2−3

=(10.375)10 Octal to Decimal:

Convert octal 630.4 8 into decimal.

(630.4)8 = 6 X 82+3 X 8+ 4 X 8-1 = (408.5)10

Hexadecimal to Decimal:

(A9F5.DE)16 = Similar as previous conversions , only consider base as 16.

a) Any base to decimal

Following Conversions are necessary:

a) Other base (binary, octal , hexadecimal) to decimal

b) Decimal to other base.

c) Binary to Octal and Hexadecimal

d) Octal and Hexadecimal Conversion

Number Base Conversions

4

Page 5: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

b) Decimal to any base

integer Reminder 41 20 1 10 0 5 0 2 1 1 0 0 1

integer Fraction 0.6875 X 2 1 0.3750 0.3750 X 2 0 0.7500 0.7500 X 2 1 0.5 0.5 X 2 1 0

Decimal to Binary:

Convert (41.6875)10 to binary.

(41)10 = (101001)2

Conversion of fractional Part:

(0.6875)10 =(0.1011)2

Conversion of integer part:

Number Base Conversions (Cont.)

5

Page 6: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Integer Part Fractional Part Integer Reminder Integer Fraction

153 0.513 X 8 4 0.104 19 1 0.104 X 8 0 0.832 2 3 0.832 X 8 6 0.656 0 2 0.656 X 8 5 0.248 0.248 X 8 1 0.984 0.984 X 8 7 0.872

Decimal to Octal:

Convert (153.513)10 to Octal

Answer: (153.513)10 = (231.406517….)8

Decimal to Hexadecimal:

Divide integer part by 16 and multiply fractional part by 16.

Number Base Conversions (Cont.)

6

Page 7: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

c) Binary to Octal and Hexadecimal Numbers

Since 23 =8 and 24 = 16, each octal digit corresponds to three binary digits and each hexadecimal digit

corresponds to four binary digits. The conversion from binary to octal is easily accomplished by

partitioning the binary numbers into groups of three digit each, starting from the binary point and

proceeding to the left and to the right.

Conversion from binary to hexadecimal is similar, except that the binary numbers is divided into

groups of four digits:

Number Base Conversions (Cont.)

7

Page 8: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

d) Conversion of Octal and Hexadecimal Numbers

Conversion from octal to hexadecimal or hexadecimal to octal is so easy if we follow the following

procedure:

Number Base Conversions (Cont.)

8

Page 9: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Number Base Conversions (Cont.)

Usefulness of Octal and Hexadecimal Numbers

A common question may arise, Human are used to in decimal number and digital systems works

with binary number. So, why should we use octal and hexadecimal numbers?

Binary numbers are difficult to work with because they require three or four times as many digits

as their decimal equivalent. For example, the binary number 111111111111 is equivalent to

decimal 4096 (hexadecimal FFF and Octal 7777).

However, digital computers use binary numbers and it is sometimes necessary for the

programmer or human operators or user to communicate directly by means of binary numbers.

When dealing with large number of binary bits, it is more convenient and less error-prone to

write the binary numbers in octal or, decimal or, hexadecimal because the numbers can be

expressed more compactly. Among these three octal and hexadecimal are more useful than

decimal because it is relatively easy to convert back and forth between binary and Hex/Octal.

9

Page 10: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Complements

Why we use complement?

Complements are used in digital computers for simplifying the subtraction operation and for logical

manipulations.

Types:

There are two types of complements for each base-r system:

a) The r’s complement and

b) The (r-1)’s complement.

r’s complement is known as 10’s complement in base 10 and 2’s complement in base 2.

(r-1)’s complement is known as 9’s complement in base 10 and 1’s complement in base 2.

10

Page 11: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Complements (Cont.)

The r’s complement:

Given a positive number N in base r with an integer part of n digits, the r’s complement of N is defined

as

The r’s complement of 𝑁 = 𝑟𝑛−𝑁, 𝑖𝑓 𝑁 ≠ 0

0, 𝑖𝑓 𝑁 = 0

Examples: 10’s complement of 52520 = 105-52520 = 47480

10’s complement of 0.3267 = 100-0.3267 = 0.6733

10’s complement of 25.639 = 102-25.639 = 74.361

2’s complement of (101100)2 = (26)10-(101100)2

= (1000000-101100)2

= 010100

2’s complement of (0.0110)2 = (20)10-0.0110 = 0.1010

11

Page 12: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Complements (Cont.)

Finding r’s complement (Simple Method):

From the definition and examples, it is clear that-

10’s complement of a decimal number can be formed –

>> By leaving all lest significant zero's unchanged.

>> subtracting the first nonzero least significant digit from 10

>> subtracting other higher significant digits from 9

Example: 10’s complement of 25.639 = 102-25.639 = 74.361

10’s complement of 52520 = 105-52520 = 47480

2’s complement can be formed by-

>> leaving all least significant zero and the first nonzero digit unchanged.

>> then replacing 1’s by 0’s and 0’s by 1’s in all other higher significant digits.

Example: 2’s complement of (101100)2 = (26)10-(101100)2= 010100

12

Page 13: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Complements (Cont.)

The (r-1)’s complement:

Given a positive number N in base r with an integer part of n digits and a fractional part of m digits,

the (r-1)’s complement of N is defined as-

The (r-1)’s complement of N = rn-r-m-N

Examples:

9’s complement of (52520)10=(105-100-52520)=47479

9’s complement of (0.3267)10 is (100-10-4-0.3267) = 0.6732

9’s complement of (25.693)10 is (102-10-3-25.693)= 74.306

1’s complement of (101100)2 is (26-20)10-(101100)2

= 111111-101100 = 010011

1’s complement of (0.0110)2 is (1-2-4)10-(0.0110)2 = 0.1001

13

Page 14: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Complements (Cont.)

Finding (r-1)’s complement (Simple Method):

>> 9’s complement of a decimal number is formed simply by subtracting every digit from 9

>> 1’s complement of a binary number is simpler: the 1’s are changed to 0’s and the 0’s to 1’s.

Example:

9’s complement of (25.693)10 is (102-10-3-25.693)= 74.306

1’s complement of (101100)2 is (26-20)10-(101100)2= 010011

Note: It is worth mentioning that the complement of the complement restores the number to it’s

original value.

r’s complement of N =rn-N and r’s complement of (rn-N) is (rn-(rn-N)) =N and similarly for the 1’s

complement.

14

Page 15: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Subtraction with Complements

Subtraction with r’s Complements

The direct method of subtraction taught in elementary schools uses the borrow concept. This

seems to be easiest when people perform subtraction with paper and pencil.

When subtraction is implemented by means of digital components, this method is found to be less

efficient than the method that uses complements and addition as stated below:

Subtraction of two positive numbers (M-N), both of base r, may be done as follows-

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

Step-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 does not occur, take the r’s complement of the number obtained in step 1

and place a negative sign in front.

15

Page 16: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Subtraction with Complements (Cont.)

Subtraction with r’s Complements (Examples)

16

Using 10’s complement, subtract 72532-3250

Let, M=72532 and N= 3250

M= 72532

10’s complement of N= 96750

End carry 1 69282 Answer: 69282

Subtract (3250-72532)10

Let, M=3250 and N= 72532

M= 03250

10’s complement of N= 27468

No carry 30718 Answer: - (10’s complement of 30718) = -69282

M=1010100 and N= 1000100.

Calculate (M-N)?

M=1010100

2’s complement of N = 0111100

End carry 1 0010000

Answer: 10000

M=1000100 and N=1010100, Calculate (M-N)

M= 1000100

2’s complement of N= 0101100

No carry 1110000

Answer: -(2’s complement of 1110000) = -10000

Page 17: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Subtraction with Complements (Cont.)

Subtraction with r’s Complements

17

Proof of the procedure:

Addition of M to r’s complement of N is given by (M+rn-N)

For numbers having an integer part of n digits, rn is equal to a 1 in the (n+1)th position (end carry).

Since M and N assumed to be positive, then:

(a) (M+rn-N) ≥ rn if M≥N or

(b) (M+rn-N) < rn if M<N

In case of (a) the answer is positive and equal to (M-N), which is directly obtained by discarding the

end carry rn.

In case of (b) the answer is negative and equal to –(N-M). This case is detected from the absence of an

end carry. The answer is obtained by taking a second complement and adding a negative sign:

-[rn+-(M+rn-N)] = -(N-M)

Page 18: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Subtraction with Complements (Cont.)

Subtraction with (r-1)’s Complements

18

The subtraction of M-N, both positive number in base r, may be calculated in the following manner:

Step-1: Add the minuend M to the (r-1)’s complement of the subtrahend N.

Step-2: Inspect the result obtained in step 1 for an end carry.

(a) If an end carry occurs, add 1 to the list significant digit (end-round carry)

(b) If an end carry does not occurs, take the (r-1)’s complement of the number obtained in

step 1 and place a negative sign in front.

Page 19: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Subtraction with Complements (Cont.)

Subtraction with (r-1)’s Complements (Example)

19

M=72532 and N=3250. Determine M-N and N-M by 9’s complement.

Finding (M-N)

M= 72532

9’s complement of N = 96749

End round carry 1 69281

+ 1

69282

Finding (N-M)

N = 03250

9’s complement of M = 27467

No carry 30717

Answer: -(9’s complement of 30717) = - 69282

M=1010100 and N=1000100. Determine (M-N) and (N-M)?

Finding (M-N)

M=1010100

1’s complement of N= 0111011

End round carry ---1 0001111

1

0010000

Answer: 10000

Finding (N-M)

N= 1000100

1’s complement of M= 0101011

No carry 1101111

Answer: -(1’s complement of 1101111) = -10000

Page 20: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Comparison between 1’s and 2’s Complement

20

1’s complement is easier to implement by digital computer than 2’s complement

The 1’s complement has the advantage of being easier to implement by digital components since the

only thing that must be done is to change 0’s into 1’s and 1’s into 0’s.

The implementation of 2’s complement may be obtained in two ways: (i) by adding 1 to the least

significant digit of the 1’s complement and (ii) by leaving all leading 0’s in the least significant positions

and the first 1 unchanged, and only then changing all 1’s into 0’s and all 0’s into 1’s.

Subtraction by 2’s complement requires less arithmetic operation.

During subtraction of two numbers by complements, the 2’s complement is advantageous in that only

one arithmetic operation is required. The 1’s complement requires two arithmetic additions when an

end-around carry occurs.

Page 21: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Comparison between 1’s and 2’s Complement (Cont.)

21

1’s complement has two arithmetic zeros.

The 1’s complement has the additional disadvantages of possessing two arithmetic zeros: one with all

0’s and one with all 1’s. To illustrate this fact, consider the subtraction of the two equal binary numbers

1100-1100=0

While the 2’s complement has only one arithmetic zero, the 1’s complement zero can be positive or

negative, which may complicate matters.

Using 1’s Complement

1100

+0011

+1111

Complement again to obtain -0000

Using 2’s Complement

1100

+0100

+0000

Page 22: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes

22

When numbers, letters or words are represented by a special group of binary symbols/combinations,

we say that they are being encoded and the group of symbols is called a code. Some familiar binary

codes are- Decimal Codes, Error-detection Codes, The Reflected Code, Alphanumeric Codes etc.

Decimal Codes

The representation of decimal digits by binary combinations is known as decimal codes. Binary codes

from decimal digits require minimum of four bits. Numerous different codes can be obtained by

arranging four or more bits in ten distinct possible combinations. Some decimal codes are-

BCD

Excess-3

84-2-1

2421

5043210 (Biquinary)

Page 23: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

23

Decimal Codes (Cont.)

Binary-Coded-Decimal (BCD) Code

If each digit of a decimal number is represented

by its binary equivalent, the result is a code

called binary coded decimal (BCD). It is

possible to assign weights to the binary bits

according to their positions. The weights in the

BCD code are 8,4,2,1.

Problem:

Convert 0110100000111001 (BCD) into its

decimal equivalent.

Convert 955 (decimal) into BCD code.

Page 24: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

24

Decimal Codes (Cont.)

Excess-3 Code

This is an unweighted code. Its code assignment is obtained from the corresponding value of BCD after

the addition of 3. It has been used in some old computers. Table 2 represents excess-3 code for

corresponding decimal digits.

Negative weights can be assigned to decimal digits by 8, 4, -2, -1. In this case the bit combination 0110 is

interpreted as the decimal digit 2, as obtained from

8x0 + 4x1 + (-2)x1 + (-1)x0 = 2.

8,4,-2,-1 Code

This one is another weighted code corresponding to the decimal digit. In this case the bit combination

1011 is interpreted as the decimal digit 5, as obtained from

2x1 + 4x0 + 2x1 + 1x1 = 5.

2,4,2,1 Code

Page 25: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

25

Decimal Codes (Cont.) Biquinary Code

The weights in the biquinary code are 5, 0, 4, 3, 2, 1, 0. The biquinary code is an example of a seven bit

code with error detection properties. Each decimal digit consists of five 0’s and two 1’s placed in the

corresponding weighted column. During transmission of signals from one location to another, an error

may occur. One or more bits may change value. A circuit in the receiving side can detect the presence

of more (or less) than two 1’s and if the received combination of bits does not agree with the allowable

combination, an error is detected.

Self-complementary Decimal Codes

From the five binary codes discussed above, the BCD seems the most natural to use and is indeed the one

most commonly encountered. The other four-bit codes listed have one characteristic in common that is

not found in BCD. The excess-3, the 2, 4, 2, 1 and the 8, 4, -2, -1 are self-complementary codes, that is,

the 9’s complement of the decimal number is easily obtained by changing 1’s to 0’s and 0’s to 1’s. (in a

Page 26: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

26

Decimal Codes (Cont.)

binary code) and subtraction is calculated by means of 9’s complement. For example, the decimal 395

is represented in the 2, 4, 2, 1 code by 0011 1111 1011. Its 9’s complement 604 is represented by 1100

0000 0100, which is easily obtained from the replacement of 1’s by 0’s and 0’s by 1’s. This property is

useful when arithmetic operations are internally done with decimal numbers

Page 27: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

27

Error-detection Codes

An error detection codes can be used to detect errors during transmission. A parity bit is an extra

bit included with a message to make the total number of 1’s either odd or even.

For a message of four bits parity (P) is chosen so that the sum of all 1’s is odd (in all five bits) or the

sum of all 1’s is even. In the receiving end, all the incoming bits (in this case five) are applied to a

“parity-check” network for checking.

An error is detected if the check parity does not correspond to the adopted one. The parity method

detects the presence of one, three or any odd combination of errors. An even combination of errors

is undetectable.

Page 28: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

28

Error-detection Codes

TX

01110 Rcv

01100

Bit error in the channel

Add

parity

bit

Message

0111

Check

Parity

Message

error if

parity even

Page 29: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

29

The Reflected Code/Grey Code

The Reflected code, also called Gray code

is unweighted and is not an arithmetic

code; that is, there are no specific weights

assigned to the bit positions.

It is a binary numeral system where two

successive values differ in only one bit

(binary digit).

For instance, in going from decimal 3 to

decimal 4, the Gray code changes from

0010 to 0110, while the binary code

changes from 0011 to 0100, a change of three bits. The only bit change is in the third bit from the

right in the Gray code; the others remain the same.

Page 30: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

30

In order to communicate, we need not only numbers, but also letters and other symbols. In the

strictest sense, alphanumeric codes are codes that represent numbers and alphabetic characters

(letters). Most such codes, however, also represent other characters such as symbols and various

instructions necessary for conveying information.

The ASCII is the most common alphanumeric code.

ASCII Code

ASCII is the abbreviation for American Standard Code for Information Interchange. Pronounced

"askee," ASCII is a universally accepted alphanumeric code used in most computers and other

electronic equipment. Most computer keyboards are standardized with the ASCII. When we enter a

letter, a number, or control command, the corresponding ASCII code goes into the computer.

Alphanumeric Codes

Page 31: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

31

ASCII has 128 characters and symbols represented by a 7-bit binary code. Actually, ASCII can be

considered an 8-bit code with the MSB always 0. This 8-bit code is 00 through 7F in hexadecimal.

The first thirty-two ASCII characters are non-graphic commands that are never printed or displayed

and are used only for control purposes. Examples of the control characters are ""null," "line feed,"

"start of text," and "escape."

The other characters are graphic symbols that can be printed or displayed and include the letters of

the alphabet (lowercase and uppercase), the ten decimal digits, punctuation signs and other

commonly used symbols.

Extended ASCII characters : In addition to the 128 standard ASCII characters, there are an

additional 128 characters that were adopted by IBM for use in their PCs (personal computers).

Because of the popularity of the PC, these particular extended ASCII characters are also used in

applications other than PCs and have become essentially an unofficial standard. The extended ASCII

characters are represented by an 8-bit code series from hexadecimal 80 to hexadecimal FF.

ASCII Code (Cont.)

Page 32: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

32

ASCII Code (Cont.)

Page 33: Binary Systems and Codes - WordPress.com · 2017-04-09 · Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC Number System

Lecture materials on "Binary Systems and Codes" By- Mohammed Abdul Kader, Assistant Professor, EEE, IIUC

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

Binary Codes (Cont.)

33

ASCII Code (Cont.)