conversion number system andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… ·...

49
Number System and Conversion Presented by: Dishant Khosla Asst. Professor

Upload: others

Post on 26-Sep-2020

34 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Number System and Conversion

Presented by:Dishant KhoslaAsst. Professor

Page 2: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Introduction

◻ Many number systems are in use in digital technology. The most common are :

Decimal (Base 10)Binary (Base 2)Octal(Base 8)Hexadecimal (Base 16)

◻ The decimal system is the number system that we use everyday

Page 3: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Number System

◻ Decimal system uses symbols (digits) for the ten values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

◻ Binary System uses digits for the two values 0, and 1 ◻ Octal System uses digits for the eight values 0, 1, 2, 3,

4, 5, 6, 7◻ Hexadecimal System uses digits for the sixteen values

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

to represent any number, no matter how large or how small.

Page 4: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

4

◻ Number systems include decimal, binary, octal and hexadecimal

◻ Each system have four number base

Number System Base Symbol

Binary Base 2 BOctal Base 8 ODecimal Base 10 DHexadecimal Base 16 H

Page 5: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Decimal System

◻ The decimal system is composed of 10 numerals or symbols. These 10 symbols are 0,1,2,3,4,5,6,7,8,9; using these symbols as digits of a number, we can express any quantity.

◻ Example : 3501.51

3 5 0 1 . 5 1

digit

decimal pointMost Significant Digit

Least Significant Digit

Page 6: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary System

◻ The binary system is composed of 2 numerals or symbols 0 and 1; using these symbols as digits of a number, we can express any quantity.

◻ Example : 1101.01

1 1 0 1 . 0 1

bit

binary pointMost Significant Bit

Least Significant Bit

Page 7: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

7

Why Binary System?

◻ Computers are made of a series of switches◻ Each switch has two states: ON or OFF◻ Each state can be represented by a number

– 1 for “ON” and 0 for “OFF”

Page 8: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary Equivalent

Page 9: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary Equivalent

Page 10: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Decimal Number Quantity (positional number)◻ 3 5 0 1 (base-10)

1 X 100 = 1

0 X 101 = 0

5 X 102 = 500

3 X 103 = 3000

3000 + 500 + 0 + 1 = 3501

Page 11: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary-to-Decimal Conversion

◻ 1 1 0 1 (base-2)

1 X 20 = 1

0 X 21 = 0

1 X 22 = 4

1 X 23 = 8 8 + 4 + 0 + 1 = 13

11012= 1310

Page 12: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Octal-to-Decimal Conversion

◻ 5 2 1 7 (base-8)

7 X 80 = 7x1 = 7

1 X 81 = 1x8 = 8

2 X 82 = 2x64 = 128

5 X 83 = 5x512 = 2560 2560 + 128 + 8 + 7 = 2703

52178 = 270310

Page 13: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Hexadecimal-to-Decimal Conversion

◻ 1 A C F (base-16) [ A = 10, B = 11, C = 12, D = 13, E = 14, F = 15 ]

15 X 160 =15x1 = 15

12 X 161 =12x16 = 192

10 X 162 =10x256 = 2560

1 X 163 = 5x4096 = 20480

20480 + 2560 +192 + 15 = 232471ACF16 = 2324710

Page 14: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Decimal Number Quantity (fractional number)◻ . 5 8 1 (base-10)

5 X 10-1 = 5x0.1 = 0.5

8 X 10-2 = 8x0.01 = 0.08

1 X 10-3 = 1x0.001 = 0.001

0.5 + 0.08 + 0.001 = 0.581

Page 15: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary-to-Decimal Conversion

◻ . 1 0 1 (base-2)

1 X 2-1 = 1x0.5 = 0.5

0 X 2-2 = 0x0.25 = 0

1 X 2-3 = 1x0.125 = 0.125

0.5 + 0 + 0.125 = 0.625

0.1012 = 0.62510

Page 16: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Octal-to-Decimal Conversion

◻ . 2 5 (base-8)

2 X 8-1 = 2x0.125 = 0.25

5 X 8-2 = 5x0.015625 = 0.017825

0.25 + 0.017825 = 0.267825

0.258 = 0.26782510

Page 17: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Hexadecimal-to-Decimal Conversion

◻ . F 5 (base-16)

15 X16-1 = 15x0.0625 = 0.9375 5 X16-2 = 5x0.00390625 = 0.01953125

0.9375 + 0.01953125 = 0.95703125

0.F516 = 0.9570312510

Page 18: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Exercise 1

◻ Convert these binary system numbers to decimal system numbers

100101101

11100.1001111111100000.0111

Page 19: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Decimal-to-Binary Conversion (positional number)◻ 2 5 0

2502 1252 Remainder 0

622 Remainder 1 312 Remainder 0152 Remainder 1 72 Remainder 1 32 Remainder 1 1 Remainder 1

25010 = 1 1 1 1 1 0 1 02

Page 20: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Decimal-to-Octal Conversion

◻ 2 5 0 2508 318 Remainder 2

3 Remainder 7

25010 = 3728

Page 21: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Decimal-to-Hexadecimal Conversion

◻ 2 5 0 25016 15 Remainder 10

25010 = 15 1016 ?= FA16

Page 22: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Decimal-to-Binary Conversion (fractional number)◻ 0 . 4375

0.4375 x 2 = 0.87500.8750 x 2 = 1.750.75 x 2 = 1.50.5 x 2 = 1.0

0.437510 = 0.01112

Page 23: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Decimal-to-Octal Conversion

◻ 0 . 4375

0.4375 x 8 = 3.50.5 x 8 = 4.0

0.437510 = 0.348

Page 24: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Decimal-to-Hexadecimal Conversion

◻ 0 . 4375

0.4375 x 16 = 7.0

0.437510 = 0.716

Page 25: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Exercise 2

◻ Convert these decimal system numbers to binary system numbers

127

3822.5764.375

Page 26: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Base X – to – Base Y Conversion

◻ We can convert base x number to base y number by following these steps :

Convert base x to base 10 (decimal system number)Then, convert decimal number to base y

Page 27: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Example

◻ Convert 372.348 to decimal system number Convert 372.348 to decimal system number■ 372.348 = (3x82)+(7x81)+(2x80) . (3x8-1) + (4x8-2)

= 192 + 56 + 2 . 0.375 + 0.0625 = 250 . 4375Convert 250.437510 to hexadecimal system number ■ 250.437510

250 / 16 = 15 remainder 10250 FA16

Positional number0.4375 * 16 = 7.0

0.4375 0.716

Fractional number

372.348 = FA.716

Page 28: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Exercise 3 (TO DO)

◻ Convert these numbers to octal system number 11100.1001211111125A.B16

◻ Convert these numbers to binary system number5A.B1675.28

Page 29: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary Addition

Page 30: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary Subtraction

Page 31: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary Multiplication

Page 32: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary Multiplication

Page 33: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary Division

Page 34: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary Division

Page 35: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

The basics: Binary numbers

◻ Addition and subtraction

1011+ 1010

10101

1011

– 0110 0101

Page 36: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary to Gray Code

Page 37: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary to Gray Code

Page 38: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Gray to Binary Code

Page 39: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Gray to Binary Code

Page 40: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Binary Coded Decimal Code

DecimalSymbols

0123456789

BCDCode0000000100100011010001010110011110001001

Page 41: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

BCD to Excess 3 Code

Page 42: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

ASCII

◻ ASCII abbreviated as American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Most modern character-encoding schemes are based on ASCII, although they support many additional characters.

Page 43: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Number systems

◻ How do we write negative binary numbers?

◻ Historically: 3 approachesSign-and-magnitudeOnes-complementTwos-complement

◻ For all 3, the most-significant bit (MSB) is the sign digit0 ≡ positive1 ≡ negative

◻ twos-complement is the important oneSimplifies arithmeticUsed almost universally

Page 44: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Sign-and-magnitude◻ The most-significant bit (MSB) is the sign digit

0 ≡ positive1 ≡ negative

◻ The remaining bits are the number’s magnitude

◻ Problem 1: Two representations for zero0 = 0000 and also –0 = 1000

◻ Problem 2: Arithmetic is cumbersome

Page 45: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Ones-complement◻ Negative number: Bitwise complement positive

number0011 ≡ 3101100 ≡ –310

◻ Solves the arithmetic problem

◻ Remaining problem: Two representations for zero0 = 0000 and also –0 = 1111

Page 46: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Twos-complement◻ Negative number: Bitwise complement plus

one0011 ≡ 3101101 ≡ –310

◻ Number wheel

00000001

0011

11111110

1100

1011

1010

1000 01110110

0100

0010

01011001

1101

0+ 1

+ 2

+ 3

+ 4

+ 5

+ 6+ 7– 8

– 7

– 6

– 5

– 4

– 3

– 2– 1

Only one zero!

MSB is the sign digit 0 ≡ positive 1 ≡ negative

Page 47: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Twos-complement (con’t)◻ Complementing a complement the original

number

◻ Arithmetic is easySubtraction = negation and addition

■ Easy to implement in hardware

Page 48: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Miscellaneous

◻ Twos-complement of non-integers1.687510 = 01.10112–1.687510 = 10.01012

◻ Sign extensionWrite +6 and –6 as twos complement

■ 0110 and 1010Sign extend to 8-bit bytes

■ 00000110 and 11111010

◻ Can’t infer a representation from a number11001 is 25 (unsigned) 11001 is –9 (sign magnitude)11001 is –6 (ones complement)11001 is –7 (twos complement)

Page 49: Conversion Number System andcgcassignments.com/wp-content/uploads/2020/07/number-system-a… · Binary System The binary system is composed of 2 numerals or symbols 0 and 1; using

Twos-complement overflow◻ Summing two positive numbers gives a negative result

◻ Summing two negative numbers gives a positive result

◻ Make sure to have enough bits to handle overflow

00000001

0011

11111110

11001011

1010

1000 01110110

0100

0010

01011001

1101

0+ 1 +

2+ 3+ 4+

5+ 6+

7– 8

– 7– 6

– 5

– 4

– 3– 2

– 10000

0001

0011

11111110

11001011

1010

1000 01110110

0100

0010

01011001

1101

0+ 1 +

2+ 3+ 4+

5+ 6+

7– 8

– 7– 6

– 5

– 4

– 3– 2

– 1

6 + 4 ⇒ –6

–7 – 3 ⇒ +6