25
Number Systems Ron Christensen CIS 121

Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Embed Size (px)

Citation preview

Page 1: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Number Systems

Ron Christensen

CIS 121

Page 2: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Positional Notation

– “Positional Notation”• Value of a digit depends on the position of the digit

– Positional Notation permits unique representation of Integers

Page 3: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Positional Notation

– Decimal numbers are “Base 10 positional notation”

• Base 10 means that the value of any position is a multiple of a power of 10

– Binary numbers are “Base 2 Positional notation”

– Octal numbers are “Base 8 Positional notation”

– Hexadecimal numbers are “Base 16”

Page 4: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

4

Positional Notation

• The value of digit n is baseN

• N0 = 1 no matter what N is

• In decimal notation the value of digit N is 10N

– “19” = 1x101 + 9x100

Page 5: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Base 10

• Base 10 uses ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

• This is called a decimal number system and is the one with which people are most familiar.

Page 6: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Why Binary?

• Build Transistor

Page 7: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Base 2

• Base 2 has exactly two symbols: 0 and 1.

• This is called a binary system and all numbers must be formed using these two symbols.

Page 8: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Base 8

• Base 8 uses eight symbols: 0, 1, 2, 3, 4, 5, 6, and 7.

• This is called an octal number system and is a convenient shorthand for base 2 numbers.

• One octal digit is the equivalent of three binary digits.

Page 9: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Base 16

• Base 16 uses sixteen symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.

• This system is called hexadecimal and can also serve as a shorthand for the binary number system.

Page 10: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Number Systems

• It is sometimes necessary or more convenient to convert numbers in one system to those in another.

Page 11: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 2(Binary) to Base 10 (Decimal)• In binary notation the value of digit N is 2N

– “1011” = 1x24 + 0x23 + 1x21 + 1x20 = 8+0+2+1 = 11

• What is the decimal value of 110110001?– 1x28 + 1x27 + 1x25 + 1x24 + 1x20

• = 256 + 128 + 32 + 16 + 1 = 433

Page 12: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 2to Base 8

• To convert base 2 to base 8, combine the binary digits from the right in groups of three and convert.

111101001011111101001011

111111 101101 001001 011011

77 55 11 33

Page 13: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 2to Base 16

• To convert base 2 to base 16, combine the binary digits from the right in groups of four and translate.

111101001011111101001011

11111111 01000100 10111011

FF 44 BB

Page 14: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 8to Base 2

• To convert base 8 to base 2, convert each octal digit into 3 binary digits.

111101001011111101001011

111111 101101 001001 011011

75137513

Page 15: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 8to Base 16

• To convert base 8 to base 16, first translate into base 2 then into base 16.

111111 101101 001001 011011

75137513

11111111 01000100 10111011

FF 44 BB

Page 16: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 10to Base 2

• To convert base 10 to base 2, divide the number repeatedly by 2; use remainders as answer.

On your own, try: 2363.On your own, try: 2363.

Page 17: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Practice

• What is the binary value of 120?• First division is 120/2. Q=60, R=0• Second division is 60/2. Q=30, R=0• Third division is 30/2. Q=15, R=0, • Fourth division is 15/2. Q=7, R=1• Fifth division is 7/ 2. Q=3, R=1• Sixth division is 3/2. Q=1, R=1• Seventh division = 1 / 2. Q=0, R=1• Quotient is zero, so we stop.• 12010 = 11110002

2

120

Page 18: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 10to Base 8

• To convert base 10 to base 8, divide the number repeatedly by 8; use remainders as answer.

On your own, try: 2363.On your own, try: 2363.

Page 19: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 10 to Base 16

• To convert base 10 to base 16, divide the number repeatedly by 16; use remainders as answer.

On your own, try: 2363.On your own, try: 2363.

Page 20: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 16to Base 2

• To convert base 16 to base 2, translate each hexadecimal digit to 4 binary digits.

On your own, try: 4BC.On your own, try: 4BC.

Page 21: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 16to Base 8

• To convert base 16 to base 8, translate to base 2 then to base 8.

On your own, try: 4BC.On your own, try: 4BC.

Page 22: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Converting Base 16to Base 10

• To convert base 16 to base 10, expand the number and translate base 16 digits to base 10.

On your own, try: 4BC.On your own, try: 4BC.

Page 23: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Practice

• The number “123DF” in decimal is– 1x164 + 2x163 + 3x162 + 13x161 + 15x160

– 65536 + 8192 + 768 + 208 + 15 = 74719

2

120

Page 24: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Number Systems

• Binary is used by hardware

• Hex numbers are used in many places– HTML color codes

• Decimal numbers appear in user interfaces

Conversions are done with calculators

Page 25: Number Systems Ron Christensen CIS 121. Positional Notation –“Positional Notation” Value of a digit depends on the position of the digit –Positional Notation

Binary Encoding – Data

• Binary numbers work well for positive integers

• Not all data is positive integer:– Negative integers– Real numbers, e.g. decimal points– Characters