introduction to numbering system

21
2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 1 Introduction to Numbering System What is a numbering system ? A method to count; know quantity Many ways to represent numbers For humans we use decimal numbering system • 0, 1, 2, ….9, pattern keeps repeating, till infinity • Why 10 digits? Not sure….. Take a guess Computers use binary numbering system Computers only understand zeros and ones • Computers are made of electronic circuit which has current flowing through it. Voltage makes the current flow • Only two levels of voltage (there are always exceptions) Zero volt = ZERO = ground = OFF +5 volt (or 3.5V) = ONE = ON

Upload: celine

Post on 15-Jan-2016

90 views

Category:

Documents


2 download

DESCRIPTION

Introduction to Numbering System. What is a numbering system ? A method to count; know quantity Many ways to represent numbers For humans we use decimal numbering system 0, 1, 2, ….9, pattern keeps repeating, till infinity Why 10 digits? Not sure….. Take a guess - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 1

Introduction to Numbering System

• What is a numbering system ?– A method to count; know quantity

• Many ways to represent numbers– For humans we use decimal numbering system

• 0, 1, 2, ….9, pattern keeps repeating, till infinity• Why 10 digits? Not sure….. Take a guess

– Computers use binary numbering systemComputers only understand zeros and ones• Computers are made of electronic circuit which has

current flowing through it. Voltage makes the current flow• Only two levels of voltage (there are always exceptions)

Zero volt = ZERO = ground = OFF+5 volt (or 3.5V) = ONE = ON

Page 2: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 2

Why?

• Why do we have numbering systems?– So we can count

• Why so many numbering systems?– Computers can only understand zeros and ones

– Decimal numbering systems started long before the dawn of computes and is easy for humans to use

– Not easy to use zeros and ones for daily use, takes to may bits to represent a small amount

• Example • 65536 in decimal takes five digits• 65536 in binary takes 16 bits

Page 3: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 3

Introduction to Numbering System

• Decimal

• Hexadecimal

• Octal

• Binary

Page 4: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 4

DecimalMost commonly used numbering system

Base 10, there are ten unique units (digits)

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Pattern starts at 0 and ends with base – 1 then keeps repeating, tens, hundreds, thousands,…

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 . . . . .. . . . . . . . . . . . . . 90 91 92 93 94 95 96 97 98 99100 101 102 103 104 105 106 107 108 109

Page 5: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 5

Hexadecimal• Used extensively in computer programming

Base 16, 16 digits, From 0 to f (0 to base –1)

0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f

0 to F 10 to FF 100 to FFF 1000 to FFFF

int x = 0xFF; // 255 in decimalint x = 0xFFFF; // 65536 in decimalint x = 0x7FFFFFFF; //2,147,483,647 in

decimal

Page 6: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 6

Octal• WAS used extensively in computer

programming a while ago, replaced by Hex• Still used in debuggers and assembly

language programs– Base 8, 8 digits from 0 to 7 ( 0 to base-1)

• 0 1 2 3 4 5 6 710 11 12 13 14 15 16 1720 21 22 23 24 25 26 27

int y = 011; // 9 in decimal

Page 7: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 7

Binary• Language of computers• Computer only understand 0s and 1s

Base 2, 2 variations of 1 bit0 and 1 (0 to base –1)

0 1 one bit = 2 unique values

00 01 10 11 two bits = 4 unique values

100 101 110 111 three bits = 8 unique values

1000 1001 1010 1011 1100 1101 1110 1111

Page 8: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 8

Bits, Bytes and Words1 byte has 8 bits

1 word has 16 bits

1 double word has 32 bits• Byte is the smallest unit of memory allocated• An int is 32 bits, one double word

• 00000001 00000010 00000011 0000010000000101 00000110 00000111 0000100000001001 00001100 00001011 00001100example: 00000001 in binary = 1 in decimal00000011 in binary = 3 in decimal

Page 9: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 9

Binary

2 bits can represent 4 (22) unique combinations

From 00 01 10 11 (0, 1, 2, 3)

4 bits can represent 16 (24) unique combinations

From 0000 (0) to 1111 (0..15)

8 bits can represent 256 (28) unique combinations

From 00000000 (0) to 11111111 (0..255) )

8 bits = 1 byte = 28 = 256 unique combinations

16 bits = 2 bytes = 216 = 65536 unique combinations

32 bits = 4 bytes = 232 = 4,294,967,296 (~ 4.2 billion)

0000 0 0001 10010 20011 30100 40101 50110 60111 71000 81001 91010 101011 111100 121101 131110 141111 15

Page 10: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 10

Binary MSB <- <- <- LSB 128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

--------------------------------------------- 0 0 0 0 0 0 0 0 = 0 0 0 0 0 0 0 0 1 = 1 0 0 0 0 0 0 1 0 = 2 0 0 0 0 0 0 1 1 = 3 (2+1) 0 0 0 0 1 1 1 1 = 15 (8+4+2+1) 0 1 1 1 0 0 0 0 = 112 (64+32+16) 1 0 0 0 0 0 0 0 = 128 128 or -1 1 1 1 1 1 1 1 1 = 255 255 or -128

8 bits = 1 byte in binary system, can represent 256 numbers

2 8 bits can represent 256 numbers

2 16 bits can represent 65536 numbers

Page 11: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 11

Conversion8 bits = 1 byte = 256 unique combinations

Binary Octal Decimal Hex

00000000000000010000001000000011000001000000010100000110000001110000100000001001000010100000101100001100000011010000111000001111

--------11111111

0123456789101112131415

---255

012345671011121314151617--

377

0123456789ABCDEF

--FF

Page 12: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 12

Conversion – bin to hex, octal

Binary Number = Octal = Hexadecimal100011010001 4321 8D1

• To convert a binary number to Octal, split binary number into pairs of three (need three binary digits to represent an octal)100 011 010 001 4 3 2 1 (bin 001 = octal 1, bin 100 = octal 4)

• To convert a binary number to hex, split binary number into pairs of four (need four binary digits to represent a hex num) 1000 1101 0001 8 D 1 (binary 1000 = hex 8 binary 1101 = decimal 13 = hex D)

Page 13: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 13

Conversion – hex, octal to bin

• Hexadecimal to Binary8D1

8 D 1

1000 1101 0001 = 100011010001

• Octal to Binary 4321

4 3 2 1

100 011 010 001 = 100011010001

Page 14: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 14

Conversion to Decimal• Binary to Decimal

Pos Val 27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1

Bin Val 1 1 0 1 0 0 1 0

(1*128) + (1*64) + (0*32) + (1*16) + (0*8) + (0*4) + (1*2) + (0*1)

128 + 64 + 0 + 16 + 0 + 0 + 2 + 0

Dec Val 210

Page 15: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 15

Conversion – Octal to Decimal

• Octal to Decimal

Positional Val 83 82 81 80

512 64 8 1

Octal Value 7 6 1 4

(7 * 512) + (6 * 64) + (1* 8) + (4*1)

3584 + 384 + 8 + 4

Octal Value was 7614

Decimal Value 3980

Page 16: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 16

Conversion – Hex to Decimal

• Hex to Decimal

Positional Val 163 162 161 160

4096 256 16 1

Hex Value A D 3 B

(A * 4096) + (D *256) + (3 * 16) + (B*1)

40960 + 3328 + 48 + 11

Hex Value was AD3B

Decimal Value is 44347

Page 17: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 17

Conversion – Decimal to Bin

• Decimal to Binary– Convert decimal 13 to Binary

Positional Val 25 24 23 22 21 20

32 16 8 4 2 10 0 1 1 0 1

first find (divisor and Modulus) operator. Is 8 > 13, no, it is OK, is 16 > 13, yes, NOT OK. Therefore first operator is 8

(13 / 8) = 1, (13 Mod 8) = 5(5 / 4) = 1, (5 mod 4) = 1(1 / 2) = 0, (1 mod 2) = 1(1 / 1) = 1, (1 mod 1) = 0Result = 1 1 0 1 in binary is decimal 13

Page 18: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 18

Conversion – Decimal to Hex

• Decimal to Hex– Convert decimal 44347 to Hex

Positional Val 163 162 161 160

4096 256 16 1

(44347 / 4096) = 10, (44347 Mod 4096) = 3387

(3387 / 256) = 13, (3387 mod 256) = 59

(59 / 16) = 3, (59 /16) = 11

(11 / 1) = 11

Result = 10, 13, 3, 11 = Hex AD3B

Page 19: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 19

Conversion – compliment• Ones compliment (~) or NOT

– Consider a 32 bit value “36”

00000000 00000000 00000000 00100100~ 11111111 11111111 11111111 11011011Simply invert the bits

• Twos compliment (~ + 1) or NOT + 1– Consider a 32 bit value “36”

00000000 00000000 00000000 00100100

~ 11111111 11111111 11111111 11011011+ 1 00000000 00000000 00000000 00000001------------------------------------------- = -36 11111111 11111111 11111111 11011100

Page 20: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 20

Conversion – compliment

-36 11111111 11111111 11111111 11011100 +36 00000000 00000000 00000000 00100100

-----------------------------------------

0 00000000 00000000 00000000 00000000

-36 + 36 = 0

Page 21: Introduction to Numbering System

2001 NHTI CP 107 M. Saleem Yusuf. 2000 Prentice Hall, Inc. All rights reserved. 21

End – Back to Lecture 2

http://www.geocities.com/msaleemyusuf/lecture_2.htm