COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll...

30
COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : • Representing concepts in a computer – Five concept types – Numbering systems: • additive • positional – How to represent our decimal number values in a computer containing on-off switches Power Tools
  • date post

    18-Dec-2015
  • Category

    Documents

  • view

    217
  • download

    4

Transcript of COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll...

Page 1: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 1What’s in the box?

Representing concepts, Part 1What we’ll cover for Part 1 :

• Representing concepts in a computer– Five concept types– Numbering systems:

• additive• positional

– How to represent our decimal number values in a computer containing on-off switches

Power Tools

Page 2: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 2What’s in the box?

• How do humans represent concepts? Examine:– Annual earnings of a UNC-CH faculty member.– Script of Gone with the Wind.– Set of fingerprints found in a police department.– Tarzan yell.– Recipe for making chicken fajitas.

• Five basic kinds of concepts (data/information)

• Want a single, common way to represent all five.– Can be encoded as numbers; which in turn can

appear as signals at the hardware level.

Representing concepts

Page 3: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 3What’s in the box?

Representing numeric values• Additive:

/ / / / /– Are any systems we use additive?

• Can some symbols have a face value other than 1?

• Positional:

– Face value • Unique symbols: represent elementary quantities.

– Place value• Value determined by position it occupies.

• Base determines how many unique symbols are used.– Raising the base to all its powers gives the place value.

– Total value: face value * place value.

Page 4: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 4What’s in the box?

Counting with ten fingers (& Arabic numbers)

0 1 2 3 4 5 6 7 8 9--Symbols represent values from 0 through 9.

--How do we represent values greater than 9? Use other symbols?

--Base?

base

place values

powers104 103 102 101 100

10,000 1,000 100 10 1

2 3 1

7 8 6 0 4 1 3

How would you describeyour algorithm tofind the total value of each number?

Page 5: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 5What’s in the box?

Suppose, we count with only 5 fingers...Symbols? WHAT has changed?? What remains same??

base

place values

powers b4 b3 b2 b1 b0

625 125 25 5 1

2 1 1 five = ??ten

4 0 3 five = ??ten

Notice base notation: numberbase

Decimal is most common, so may omit base notation.

Suppose, we count with only 2 fingers...

Base? Number of symbols?Quiz: How would you represent the value 2?

0 1 2 3 4

Page 6: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 6What’s in the box?

base

place values

powers 26 25 24 23 22 21 20

64 32 16 8 4 2 1 0 1 1 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0

Notice as you read down, looks somewhat like an advancing odometer:

Note 0 as “place holder” for the least significant digits with 0 value.

Page 7: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 7What’s in the box?

100000 10000 1000 100 10 1 0 1 2 3 4 5 6 7 8 9

base

place values

powers 105 104 103 102 101 100

Same thing for base ten:

1 0 1 1 1 2 ... 2 0 ... 9 9 ... 1 0 0

Page 8: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 8What’s in the box?

Positional systems

• What determines number of unique symbols used in a positional numbering system, then?

• What determines value of each position?

• Here’s a number: 1110– What value does it represent? (what is its decimal

equivalent?)

But WAIT!…what’s the problem here?

Page 9: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 9What’s in the box?

Base 10 place values: 10,000 1,000 100 10 1

625 125 25 5 1Base 5 place values:

16 8 4 2 1Base 2 place values:

1 1 1 0 base xFace values:

Dec.Value:Same algorithm: Sum of (face*place) =Base x:

Base 10:

Base 5:

Base 2:

1*1000 + 1*100 + 1*10 + 0*1 =

1* 125 + 1*25 + 1*5 + 0*1 =

1* 8 + 1* 4 + 1*2 + 0*1 =

1,110

155

14

Page 10: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

Even more fingers…….Hexadecimal

– 0 1 2 3 4 5 6 7 8 9

BEEF16 What is its decimal equivalent?

164 163 162 161 160 base

place values

face values

powers

65,536 4,096 256 16 1

B E E F 16

What algorithm do you use to find total value?

11*4096 + 14*256 + 14*16 + 15*1 = 48,87910

A B C D E F 10 11 12 13 14 15 dec value

• Base 16: quick---how many fingers…or symbols?

2 A D

10

= 68510

Page 11: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

Hexadecimal ... used by Programmers!

• for “looking” at the actual bits that are stored in memory (e.g. memory dump)

• for “specifying” binary data. HEXadecimal is an efficient shorthand notation for Binary

• one HEX symbol specifies 4 bits

01101110 = 6E 11111111 = FF

HEX BI HEX BI HEX BI HEX BI

0 0000 4 0100 8 1000 C 11001 0001 5 0101 9 1001 D 11012 0010 6 0110 A 1010 E 11103 0011 7 0111 B 1011 F 1111

Page 12: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 12What’s in the box?

Positional values• These are legal in their respective bases:

– A489C16 – 356728 – 24415

• These are not: why?– 87728

– 3A576910

– 112112

QUOTABLE

• Base affects value! (place values change)– 324510 is not equal to 32456

– But: 1510 = 11112 = F16

Page 13: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 13What’s in the box?

Simple to convert from any base to a decimal base; or from a decimal base to another base

• Converting a base-x number to a decimal number

e.g.: 2134 = ?10

– first, find place values (how???)

base

place values

(face values)

powers 43 42 41 40

64 16 4 1

2 1 34

– second, find total values (how???)

2*16 + 1*4 + 3*1 = 39

Tot Value = SUM of (each face value * each place value)

Page 14: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 14What’s in the box?

Converting a decimal number into base-x number

– first, determine symbols (face values) used in base x. (How?)

– second, find place values for base x. (How?)

– Start far left as reasonable, and try largest face value: does it fit? If so, fill in. If not, try next smallest face value. Repeat.

• In other words: Fill in table with enough numbers until it totals desired decimal value--sort of reversing the algorithm.

Example: 3710 is represented how in base two? --Symbols in base two? (face values)--Place values? --Fill in table, starting left ...

base

place valuesface values

powers

64 32 16 8 4 2 1 26 25 24 23 22 21 20

1 0 0 1 0 1

Page 15: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 15What’s in the box?

• Get with 1 or 2 neighbors: Try these now:

(a) Convert 12123 to a base 10 number

(b) Convert 45 to a base 2 number

(c) Convert 45 to a base 4 number

Page 16: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 16What’s in the box?

(a) Convert 12123 to a base 10 number

34 33 32 31 30

81 27 9 3 1

base

place values

powers

1 2 1 23

1*27 + 2*9 + 1*3 + 2*1 = 50

12123 = ?

10

Page 17: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

(a) Convert 45 to a base 2 number

26 25 24 23 22 21 20

64 32 16 8 4 2 1

base

place values

powers

1 0 1 1 0 1

4510 = ?2

--We KNOW the place values.

--We are LOOKING for correct FACE values to plug in to the table!

--1st: What symbols can we use in this base?--2nd: Where should we place which symbols in the table

(until it equals our total of 45)?

Start left, trying largest face value….work your way right.16

Page 18: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

(a) Convert 45 to a base 4 number

45 44 43 42 41 40

1024 256 64 16 4 1

base

place values

powers

4510 = ?4

2 3 1--We KNOW the place values.

--We are LOOKING for correct FACE values to plug in to the table!

--1st: What symbols can we use in this base?--2nd: Where should we place which symbols in the table

(until it equals our total of 45)?

Start left, trying largest face value….work your way right.17

Page 19: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 19What’s in the box?

• To represent an integer value in some base x, how many correct answers are there?

1310 = ?x for x ranging from 2 to

infinity1310 = 11012

1310 = 1113

1310 = 314

1310 = 235

1310 = 216

1310 = 167

1310 = 158

1310 = 149

1310 = 1310

1310 = 1211

1310 = 1112

1310 = 1013

1310 = D14

1310 = D15

1310 = D16...

Page 20: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 20What’s in the box?

• Divide decimal number by base number X.• Write the quotient• Write the remainder by the side• Keep dividing as long as quotient isn’t zero.• Read answer from remainder side in

reverse order.

• Can also use a division algorithm to convert a decimal number to some base x number.

example 4410 = ?

244 / 2 = 22/ 2 = 11/ 2 = 5/ 2 = 2/ 2 = 1 / 2 = 0

0 0 1 1 10

00111 0quotient

remainder

Page 21: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 21What’s in the box?

• Base 10: DECImal numbering system

• Base 2: BInary numbering system

• Any base number can be converted to binary.

• But WHY BINARY? ….

Voltage

0

1.0

0

1

Binary

0123456789

Decimal

Page 22: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 22What’s in the box?

• Logical structure, then:– Binary 0s and 1s: Binary digits. Bits.

– Bit: smallest, most basic data unit in a computer. • So how do we represent a bit “in the box”?

1

0=

Etc?

0 0 0 0=

0 0 1 0=

8 4 2 1 (place values)

=0 0 0 1

0 1 0 0=

=0 0 1 1

0

1

2

3

4

Page 23: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 23What’s in the box?

• Binary numbers: general & powerful common representation for all these types:

Numeric valuesCharactersVisualAudioInstructional

Encode as binary numbers(logical structure)

0 1

Appear as on/offsignals at thehardware level (physical structure)

Page 24: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 24What’s in the box?

Numeric values in binary systems

•Whole numbers (pos & neg): we generally use a fixed # of bits. 32 bits allows for a positive value of >2 billion.

#bits #possib’s

1 21 2

2 22 4

4 24 16

8 28 256

16 216 65536

32 232 4,294,967,296 (~half positive)

Page 25: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 25What’s in the box?

– We use special mathematical conventions to represent negative numbers and fractions.

– The details are shown on the following two slides, but are just for culture.

Page 26: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 26What’s in the box?

•Excess notation– sign = most significant bit

– not generally used

Negative numbers

•Two’s complement notation– fixed # digits to represent each whole number (eg. 6 used here)– zero: all 0’s (000 000)– positive numbers:

• like before, but have leading 0’s

510 000 1012 – finding a negative number:

• take complement and add 1:

- 510 - 000 1012 111 0102 + 000 0012 111 0112

number

15 bits1 bit

number

16 bits

0000000000000101 5-51000000000000101

0000000000000101 51111111111111011 -5

Page 27: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 27What’s in the box?

•Fixed point notation– add a decimal point:

•Floating point notation is used to represent fractions. (Or real numbers with a limited precision.)– high order bit is sign bit

– remaining bits used for exponent and mantissa

– decimal point placed to left of mantissa; exponent shifts radix

23 22 21 20 2-1 2-2 2-3

1 0 1 1 . 0 1 1 = 8 + 2 + 1 + 0.25 + 0.125= 11.375

Floating point notation

(1+m)2e

me+127

23 bits8 bits1 bit

01000000101110000000000000000000 = 5.75

Page 28: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 28What’s in the box?

Digression: Limitations on precision•Think of repeating decimals: what’s the problem here?

– 1/3 = 0.3333333...

•The same thing can happen in binary, but with different numbers.

•Converting back and forth with a fixed number of places, we can end up with unexpected round-off errors.

•Experiment: try 1 3 (press =) 3 on different calculators.

Page 29: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 29What’s in the box?

So what’s an important POINT here?

Page 30: COMP 4—Power Tools for the Mind 1 What’s in the box? Representing concepts, Part 1 What we’ll cover for Part 1 : Representing concepts in a computer –Five.

COMP 4—Power Tools for the Mind 30What’s in the box?

Recall a question from Lec-01 overview:• How can hardware that can represent only whole number

values (with on/off switches) be used to represent more complex data values (real numbers, negative numbers, …)?

ANSWER? New data types can be defined—similar to the way that complex transformations can be defined—by software.

• The rules people define for transforming data will depend on the representations that we choose for the data.

• We’ll soon see how other kinds of complex data are represented.