Numbers - the essence

A computer consists in essence of a sequence of electrical on/off switches.

Big question: How do switches become a computer?

ITEC 1000 Introduction to Information Technologies 1 Friday, September 25, 2009 • A single switch is called a bit • A sequence of 8 bits is called a byte • Two or more bytes are often grouped to form word

• Modern laptop/desktop standardly will have memory of 1 gigabyte = 1,000,000,000 bytes

ITEC 1000 Introduction to Information Technologies 2 Friday, September 25, 2009 Question: How do encode information with switches ?

Answer: With numbers - binary numbers using only 0’s and 1’s where for each switch

on position = 1 off position = 0

ITEC 1000 Introduction to Information Technologies 3 Friday, September 25, 2009 • For a byte consisting of 8 bits there are a total of 28 = 256 ways to place 0’s and 1’s.

Example 0 1 0 1 1 0 1 1

• For each grouping of 4 bits there are 24 = 16 ways to place 0’s and 1’s. • For a byte the first and second groupings of four bits can be represented by two digits • this will be made clear in following slides.

ITEC 1000 Introduction to Information Technologies 4 Friday, September 25, 2009 Bits & Bytes imply

creation of data and computer analysis of data

• storing data (reading) • processing data - operations, evaluations & comparisons • output of results

ITEC 1000 Introduction to Information Technologies 5 Friday, September 25, 2009 Numeral systems

A is any method of symbolically representing the counting numbers

1, 2, 3, 4, 5, ......

What was just written is one such symbolic system

ITEC 1000 Introduction to Information Technologies 6 Friday, September 25, 2009 Chinese numerals Starting 4th century BC a numeral system evolved based on a counting board with numbers represented by little rods of bamboo or ivory Two representations for numbers 1 to 9

Possible confusion: | | | could be 3, 12, 21, or 111 Solution: alternate top and bottom patterns in diagram above

equals 1234

equals 60390 more chinese numerals

ITEC 1000 Introduction to Information Technologies 7 Friday, September 25, 2009 Ancient Egyptian numerals circa 3000 BC

Based on hieroglyphs representing powers of 10. A number represented by a string of such symbols - to evaluate one adds up the values of the symbols.

Thus

More Ancient Egyptian

ITEC 1000 Introduction to Information Technologies 8 Friday, September 25, 2009 Ancient

• One of early Greek numeral systems used alphabetic symbols to represent numbers. • Symbols could occur in any order and the value was determined by adding the value of the symbols • 3 of the symbols, digamma, koppa, and sampi are older Phoenician letters

Thus: αµεν =1+ 40 + 5 + 50

more ancient Greek

ITEC 1000 Introduction to Information Technologies 9 Friday, September 25, 2009

Still used today - extensively until mid 1800’s

Again, numbers represented by the | 1 sum values of the symbols V 5 X 10 Thus: MMCXXV1 = 2126 L 50 C 100 D 500 More Roman numerals M 1000

ITEC 1000 Introduction to Information Technologies 10 Friday, September 25, 2009 Positional numeral systems

Given a number a number b called the base and symbols for numbers from zero up to value of b-1.

Value of a symbol in the kth position in a string of symbols is

the value of symbol times the value of (b)k-1

Thus when b = 10 and symbols for the numbers from zero to b-1 are the Hindu-Arabic symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

3256 = 3 × 103 + 2 × 102 + 5 × 101 + 6 × 100

More on positional numeral systems

ITEC 1000 Introduction to Information Technologies 11 Friday, September 25, 2009 Ancient Babylonian numeral system A positional system with base b = 60 using two symbols - the symbol for one and the symbol for ten

Thus 1× 603 + 57 × 602 + 46 × 60 + 40 =

More on Babylonian numerals

ITEC 1000 Introduction to Information Technologies 12 Friday, September 25, 2009 In our usual positional number system, the meaning of a digit depends on where it is located in the number

Example: 3 7 3 2

3 groups of 1000 7 groups of 100 3 groups of 10 2 groups of 1 3 2 Thus: 372 = 3x10 + 7x10 + 3x10 + 2 /KC

ITEC 1000 Introduction to Information Technologies 13 Friday, September 25, 2009 In world of computers - other than base 10 positional - following positional systems used

• base b = 2 - binary system with symbols: 0 and 1

• base b = 8 - system, with symbols: 0,1, 2, 3, 4, 5, 6, 7

• base b = 16 - hexadecimal system with symbols 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F where letters have the following values

A = 10, B =11, C =12, D =13, E =14, F =15

ITEC 1000 Introduction to Information Technologies 14 Friday, September 25, 2009 Examples

In binary: 5 4 3 2 1 0 (101101)2 = 1× 2 + 0 × 2 + 1× 2 + 1× 2 + 0 × 2 + 1× 2 = 32 + 8 + 1 = 41 In octal 3 2 1 0 (6721)8 = 6 × 8 + 7 × 8 + 2 × 8 + 2 × 8 = 6 × 512 + 7 × 64 + 16 + 2 = 3538

In hexadecimal (hex):

3 2 (A1CE)16 = 10 × 16 + 1× 16 + 12 × 16 + 15 = 40960 + 256 + +192 + 15 = 41423

ITEC 1000 Introduction to Information Technologies 15 Friday, September 25, 2009 Counting in different bases

Base 10 Base 2 Base 16 0 0 0 1 1 1 2 10 2 3 11 3 4 100 4 5 101 5 6 110 6 7 111 7 8 1000 8 9 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E

ITEC 1000 Introduction to Information Technologies 16 Friday, September 25, 2009 Conversions - number y to base b

Goal: Express y as a sum of multiples of powers of b

• Given number y • loop: • find greatest power k of b such that bk ≤ y. • find greatest multiple ck of b where 0 ≤ ck ≤ b-1 k • such that ckb ≤ y • set ck as (k+1)st digit of base b expansion of y k • set y = y - ckb

• if k =1, set c0 = y - bc1 and stop • otherwise go to loop and continue

ITEC 1000 Introduction to Information Technologies 17 Friday, September 25, 2009 Example - decimal to hexadecimal:

Given decimal number 787, find hex equivalent

For left most hex digit - look for largest multiple ( 1 through 15) of a power of 16 whose value is less than 787. Some powers of 16 are : 162 = 256 163 = 4096 164 = 65,536

ITEC 1000 Introduction to Information Technologies 18 Friday, September 25, 2009 Method as follows Since 163 > 787, look for largest multiple ( 1 through 15) of 162 = 256 which is less than 787

Divide 256 into 787 getting 787 = 768 + 19 = 3 x 256 + 19 Repeat process with the remainder 19. Highest power of 16 ≤ 19 is 1 and highest multiple of 16 ≤ 19 is also 1. Thus 787 = 3 x 162 + 1 x 161 + 3 x 160

78710 = 313H

ITEC 1000 Introduction to Information Technologies 19 Friday, September 25, 2009 Decimal to binary

Example: Convert 78710 to binary Somewhat easier - find the highest power of 2 ≤ 787

Powers of two are 21 = 2 27 = 128 22 = 4 28 = 256 23 = 8 29 = 512 24 = 16 210 = 1024 25 = 32 211 = 2048 26 = 64 212 = 4096

ITEC 1000 Introduction to Information Technologies 20 Friday, September 25, 2009 Highest power of 2 ≤ 787 is 29 = 512

787 = 512 + 275 = 29 + 275

Repeat with remainder 275 What is highest power of 2 ≤ 275? Answer - 256 = 28 787 = 29 +28 + 19 Repeat with remainder 19 - writing 19 as a sum of powers of 2 19 = 16 +2 +1 = 24 + 21 + 20

Result: 787 = 29 + 28 + 24 + 21 + 20 = 1x29 + 1x28 + 0x27 +0x26 + 0x25 + 1x24 + 0x23 + 1x21 + 1x20

78710 = 1100010112

ITEC 1000 Introduction to Information Technologies 21 Friday, September 25, 2009 More Decimal to binary:

Given decimal number 115 • highest power of 2 ≤ 115 is 64 = 26 • 115 = 26 + 51 • highest power of 2 ≤ 51 is 32 = 25 and 51 = 25 + 19 • 115 = 26 + 25 + 19 • highest power of 2 ≤ 19 is 16 = 24 and 19 = 24 + 3 • 115 = 1x26 + 1x25 + 1x24 + 0x23 + 0x22 + 1x21 +1x20 Binary value: 1110011

ITEC 1000 Introduction to Information Technologies 22 Friday, September 25, 2009 Binary to hexadecimal

Example: 10 1011 10112 = ?H

Group binary digits in groups of 4 starting at right end - some perhaps left over at left end Translate each group into hex 10 1011 1011 binary

2 B B hex Result

10101110112 = 2BB16

ITEC 1000 Introduction to Information Technologies 23 Friday, September 25, 2009 Hexadecimal to binary Convert each hexadecimal digit to a 4-bit equivalent binary representation

Example: Convert 10AF to binary 1 0 A F

0001 0000 1010 1111

Answer : 10AFH = 10000101011112

ITEC 1000 Introduction to Information Technologies 24 Friday, September 25, 2009 Observation

• One long string of 0’s and 1’s hard to remember - hard to see. • Binary is awkward for the human brain • Hexadecimal is a compact way of representing binary • Conversions back and forth are easy

ITEC 1000 Introduction to Information Technologies 25 Friday, September 25, 2009 Alternate Method

The method introduced proceeds from first principles calculating first the left most digit of the new representation.

The alternate method calculates right most digit first • involves conceptional trick • computationally more simple

ITEC 1000 Introduction to Information Technologies 26 Friday, September 25, 2009 Example: Express 347(10) as base 8 numeral of form

2 1 c2 8 + c1 8 + c0 • Divide 8 into 347: 347 = 43⋅ 8 + 3.

• Thus c0 = 3 and the other coefficients c1 and c2 are buried in 43 • Divide 43 by 8: 43 = 5 ⋅ 8 + 3

• Thus: 347 = (5 ⋅ 8 + 3)8 + 3 = 5 ⋅ 82 + 3⋅ 81 + 3

• Thus: 347(10) = 533(8)

ITEC 1000 Introduction to Information Technologies 27 Friday, September 25, 2009 Example: Express 4782(10) as hexadecimal

• Divide 16 into 4782 to find first digit. 4782 = 298 ⋅16 + 14 • Divide 16 into 298 to find 2nd digit 298 = 18 ⋅16 + 10 • Thus:4782 = (18 ⋅16 + 10)⋅16 + 14 = 18 ⋅162 + 10 ⋅16 + 14 • Divide 16 into 18 4782 = (1⋅16 + 2)162 + 10 ⋅16 + 14 = 1⋅163 + 2 ⋅162 + 10 ⋅16 + 14

• Thus: 4782(10) = 12AE(16)

ITEC 1000 Introduction to Information Technologies 28 Friday, September 25, 2009 Exercise – Convert ...

Hexa- Decimal Binary Octal decimal

33 1110101 703 1AF Don’t use a calculator! Answer

ITEC 1000 Introduction to Information Technologies 29 Friday, September 25, 2009 Answer

Hexa- Decimal Binary Octal decimal

33 100001 41 21 117 1110101 165 75 451 111000011 703 1C3 431 110101111 657 1AF

ITEC 1000 Introduction to Information Technologies 30 Friday, September 25, 2009