Top Banner
1 Number System Lecture 2
31
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 2 ns

1

Number System

Lecture 2

Page 2: Lecture 2 ns

2

Introduction to Number Systems

• We are all familiar with the decimal number system (Base 10). Some other number systems that we will work with are:

• Binary Base 2• Octal Base 8• Hexadecimal Base 16

Page 3: Lecture 2 ns

3

Characteristics of Numbering Systems

1) The digits are consecutive.2) The number of digits is equal to the size of

the base.3) Zero is always the first digit.4) The base number is never a digit.5) When 1 is added to the largest digit, a sum

of zero and a carry of one results.6) Numeric values determined by the implicit

positional values of the digits.

Page 4: Lecture 2 ns

4

Significant Digits

Decimal: 82347

Most significant digit Least significant digit

Binary: 101010

Most significant digit Least significant digit

Page 5: Lecture 2 ns

5

Binary Number System

• Also called the “Base 2 system”• The binary number system is used to model

the series of electrical signals computers use to represent information

• 0 represents the no voltage or an off state• 1 represents the presence of voltage or an

on state

Page 6: Lecture 2 ns

6

Binary Numbering Scale

Base 2 Number

Base 10 Equivalent

PowerPositional

Value

000 0 20 1

001 1 21 2

010 2 22 4

011 3 23 8

100 4 24 16

101 5 25 32

110 6 26 64

111 7 27 128

Page 7: Lecture 2 ns

7

Binary Addition

4 Possible Binary Addition Combinations:(1) 0 (2) 0

+0 +1

00 01

(3) 1 (4) 1

+0 +1

01 10

SumCarry

Note that leading zeroes are frequently dropped.

SumCarry

Page 8: Lecture 2 ns

8

Decimal to Binary Conversion

• The easiest way to convert a decimal number to its binary equivalent is to use the Division Algorithm

• This method repeatedly divides a decimal number by 2 and records the quotient and remainder • The remainder digits (a sequence of zeros and

ones) form the binary equivalent in least significant to most significant digit sequence

Page 9: Lecture 2 ns

9

Division Algorithm

Convert 67 to its binary equivalent:

6710 = x2

Step 1: 67 / 2 = 33 R 1 Divide 67 by 2. Record quotient in next row

Step 2: 33 / 2 = 16 R 1 Again divide by 2; record quotient in next row

Step 3: 16 / 2 = 8 R 0 Repeat again

Step 4: 8 / 2 = 4 R 0 Repeat again

Step 5: 4 / 2 = 2 R 0 Repeat again

Step 6: 2 / 2 = 1 R 0 Repeat again

Step 7: 1 / 2 = 0 R 1 STOP when quotient equals 0

1 0 0 0 0 1 12

Page 10: Lecture 2 ns

10

Binary to Decimal Conversion

• The easiest method for converting a binary number to its decimal equivalent is to use the Multiplication Algorithm

• Multiply the binary digits by increasing powers of two, starting from the right

• Then, to find the decimal number equivalent, sum those products

Page 11: Lecture 2 ns

11

Multiplication Algorithm

Convert (10101101)2 to its decimal equivalent:

Binary 1 0 1 0 1 1 0 1

Positional Values

xxxxxxxx2021222324252627

128 +0+32 +0+ 8 + 4 +0+ 1

Products

17310

Page 12: Lecture 2 ns

12

Octal Number System

• Also known as the Base 8 System• Uses digits 0 - 7• Readily converts to binary • Groups of three (binary) digits can be used to

represent each octal digit• Also uses multiplication and division algorithms for

conversion to and from base 10

Page 13: Lecture 2 ns

13

Decimal to Octal Conversion

Convert 42710 to its octal equivalent:

427 / 8 = 53 R 3 Divide by 8; R is LSD

53 / 8 = 6 R 5 Divide Q by 8; R is next digit

6 / 8 = 0 R 6 Repeat until Q = 0

6538

Page 14: Lecture 2 ns

14

Octal to Decimal Conversion

Convert 6538 to its decimal equivalent:

6 5 3xxx

82 81 80

384 + 40 + 3

42710

Positional Values

Products

Octal Digits

Page 15: Lecture 2 ns

15

Octal to Binary Conversion

Each octal number converts to 3 binary digits

To convert 6538 to binary, just substitute code:

6 5 3

110 101 011

Code

0 0 0 0

1 0 0 1

2 0 1 0

3 0 1 1

4 1 0 0

5 1 0 1

6 1 1 0

7 1 1 1

Page 16: Lecture 2 ns

16

Hexadecimal Number System

• Base 16 system• Uses digits 0-9 &

letters A,B,C,D,E,F• Groups of four bits

represent eachbase 16 digit

Page 17: Lecture 2 ns

17

Decimal to Hexadecimal Conversion

Convert 83010 to its hexadecimal equivalent:

830 / 16 = 51 R 14

51 / 16 = 3 R 3

3 / 16 = 0 R 3

33E16

= E in Hex

Page 18: Lecture 2 ns

18

Hexadecimal to Decimal Conversion

Convert 3B4F16 to its decimal equivalent:

Hex Digits

3 B 4 Fxxx

163 162 161 160

12288 +2816 + 64 +15

15,18310Positional Values

Products

x

Page 19: Lecture 2 ns

19

Binary to Hexadecimal Conversion

• The easiest method for converting binary to hexadecimal is to use a substitution code

• Each hex number converts to 4 binary digits

Page 20: Lecture 2 ns

20

Convert 0101011010101110011010102 to hex using the 4-bit substitution code :

0101 0110 1010 1110 0110 1010

Substitution Code

5 6 A E 6 A

56AE6A16

Page 21: Lecture 2 ns

21

Substitution code can also be used to convert binary to octal by using 3-bit groupings:

010 101 101 010 111 001 101 010

Substitution Code

2 5 5 2 7 1 5 2

255271528

Page 22: Lecture 2 ns

22

Complement

• Complement is the negative equivalent of a number.

• If we have a number N then complement of N will give us another number which is equivalent to –N

• So if complement of N is M, then we can say M = -N So complement of M = -M = -(-N) = N

• So complement of complement gives the original number

Page 23: Lecture 2 ns

23

Types of Complement

• For a number of base r, two types of complements can be found• 1. r’s complement

• 2. (r-1)’s complement

• Definition:• If N is a number of base r having n digits then

• r’s complement of N = rn – N and • (r-1)’s complement of N = rn-N-1

Page 24: Lecture 2 ns

24

Example

• Suppose N = (3675)10

• So we can find two complements of this number. The 10’s complement and the 9’s complement. Here n = 4

• 10’s complement of (3675) = 104-3675

= 6325• 9’s complement of (3675) = 104-3675 -1

= 6324

Page 25: Lecture 2 ns

25

Short cut way to find (r-1)’s complement

• In the previous example we see that 9’s complement of 3675 is 6324. We can get the result by subtracting each digit from 9.

• Similarly for other base, the (r-1)’s complement can be found by subtracting each digit from r-1 (the highest digit in that system).

• For binary 1’s complement is even more easy. Just change 1 to 0 and 0 to 1. (Because 1-1=0 and 1-0=1)

Page 26: Lecture 2 ns

26

Example:

• (110100101)2 1’s complement 001011010

• (110100101)2 2’s complement 001011011

Page 27: Lecture 2 ns

27

Use of Complement

• Complement is used to perform subtraction using addition• Mathematically A-B = A + (-B)• So we can get the result of A-B by adding complement of B

with A.• So A-B = A + Complement of (B)• Now we can use either r’s complement or (r-1)’s

complement

Page 28: Lecture 2 ns

28

Complementary Arithmetic

• 1’s complement• Switch all 0’s to 1’s and 1’s to 0’s

Binary # 10110011

1’s complement 01001100

Page 29: Lecture 2 ns

29

Complementary Arithmetic

• 2’s complement• Step 1: Find 1’s complement of the number

Binary # 110001101’s complement 00111001

• Step 2: Add 1 to the 1’s complement00111001

+ 0000000100111010

Page 30: Lecture 2 ns

30

Complementary Arithmetic

1000 8 8

-100 -4 6

14

1000 100

Add 2’s Com 100 1’s complement 011

Discard MSB 1100 2’s complement 100

Result 100

Addition, subtraction, multiplication and division all can be done by only addition.

Page 31: Lecture 2 ns

31

Thank You