Top Banner
LECTURE 7: COMPUTERS AS STORAGE CSC 107 – Programming For Science
27

CSC 107 – Programming For Science. Positional Notation Used in nearly all modern numerical systems Right-to-left ordering of digits within larger.

Jan 03, 2016

Download

Documents

Stuart Cain
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

LECTURE 7:COMPUTERS AS STORAGE

CSC 107 – Programming For Science

Page 2: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Positional Notation

Used in nearly all modern numerical systems Right-to-left ordering of digits within larger

number Expresses value using value of each digit

(0, 1, 2, … 9) Value of position in which the digit is places e.g., 3, 13, 913, 0913, 10913, 810913

Numbers & arithmetic easy to understand Subtracting roman numerals is not for faint-

of-heart

Page 3: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Positional Notation for 58622 = 2 ones = 2 * 1 = 2

Page 4: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Positional Notation for 58622 = 2 ones = 2 * 1 = 2

6 = 6 tens = 6 * 10 = 60

Page 5: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Positional Notation for 58622 = 2 ones = 2 * 1 = 2

6 = 6 tens = 6 * 10 = 60

8 = 8 hundreds = 8 * 100 = 800

Page 6: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Positional Notation for 58622 = 2 ones = 2 * 1 = 2

6 = 6 tens = 6 * 10 = 60

8 = 8 hundreds = 8 * 100 = 800

5 = 5 thousands = 5 * 1000 = 5000

Page 7: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Positional Notation for 58622 = 2 ones = 2 * 1 = 2

6 = 6 tens = 6 * 10 = 60

8 = 8 hundreds = 8 * 100 = 800

5 = 5 thousands = 5 * 1000 = + 5000

5862

Page 8: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Decimal Positional Notation

Formal equation for a number dn...d3d2d1d0 d0 is digit in ones place, d1 is in tens place,

…d0 * 100

d1 * 101

d2 * 102

d3 * 103

+ dn * 10n

Page 9: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Base-10 Positional Notation

d0 2 = 2 ones = 2 * 1 = 2

d1 6 = 6 tens = 6 * 10 = 60

d2 8 = 8 hundreds = 8 * 100 = 800

d3 5 = 5 thousands = 5 * 1000 = + 5000

5862

Page 10: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Base-10 Positional Notation

d0 2 = 2 ones = 2 * 100 = 2

d1 6 = 6 tens = 6 * 101 = 60

d2 8 = 8 hundreds = 8 * 102 = 800

d3 5 = 5 thousands = 5 * 103 = + 5000

5862

Page 11: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Base-10 Positional Notation

d0 2 = 2 ones = 2 * 100 = 2

d1 6 = 6 tens = 6 * 101 = 60

d2 8 = 8 hundreds = 8 * 102 = 800

d3 5 = 5 thousands = 5 * 103 = + 5000

5862

Page 12: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Base-10 Positional Notation

d0 2 = 2 ones = 2 * 100 = 2

d1 6 = 6 tens = 6 * 101 = 60

d2 8 = 8 hundreds = 8 * 102 = 800

d3 5 = 5 thousands = 5 * 103 = + 5000

5862

Page 13: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Computer Number Systems

Previous equation worked in decimal (base-10) Usual number system used in day-to-day

life System requires representing 10 different

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

Computers always in one of two states Turned on, your PS3 can play Guitar Hero 3 Cell phones great paperweights when

turned off Binary digits (0,1) only used by

computers To use them, helps to know powers-of-two

bases

Page 14: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Digits In Other Bases

Binary (base-2) uses 2 digits: 0, 1

Octal (base-8) uses 8 digits: 0, 1, 2, 3, 4, 5, 6, 7

Hexadecimal (base-16) has 16 digits:0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

A16 = 1010 D16 = 1310

B16 = 1110 E16 = 1410

C16 = 1210 F16 = 1510

Page 15: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Positional Notation

To convert dn...d3d2d1d0 into decimal:

From base-10d0 * 100

d1 * 101

d2 * 102

d3 * 103

+ dn * 10n

Page 16: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Positional Notation

To convert dn...d3d2d1d0 into decimal:

From base-bd0 * b0

d1 * b1

d2 * b2

d3 * b3

+ dn * bn

Page 17: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Converting Binary to Decimal1010112 = d0

d1

d2

d3

d4

d5

Page 18: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Converting Binary to Decimal1010112 = d0 1 *

d1 1 *

d2 0 *

d3 1 *

d4 0 *

d5 1 *

Page 19: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Converting Binary to Decimal1010112 = d0 1 * 20 =

d1 1 * 21 =

d2 0 * 22 =

d3 1 * 23 =

d4 0 * 24 =

d5 1 * 25 =

Page 20: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Converting Hex to Decimal

2716 = d0

d1

3F16 = d0

d1

Page 21: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Converting Hex to Decimal

2716 = d0 716= 710

d1 216= 210

3F16 = d0 F16=1510

d1 316= 310

Page 22: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Converting Hex to Decimal

2716 = d0 716= 710 * 160 =

d1 216= 210 * 161 =

3F16 = d0 F16=1510 * 160 =

d1 316= 310 * 161 =

Page 23: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Positional Notation Review

To convert dn...d3d2d1d0 into decimal:

From base-bd0 * b0

d1 * b1

d2 * b2

d3 * b3

+ dn * bn

Page 24: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Converting Decimal To Binary Converting from decimal to binary

(base-2):While decimal number ≠ 0

Divide decimal number by 2Move remainder to left end of

answerReplace decimal number with

quotient

3410 =

Page 25: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Converting Decimal To Base-b More generally, convert from decimal

to base-b: While decimal number ≠ 0

Divide decimal number by bMove remainder to left end of

answerReplace decimal number with

quotient

33510 = 16

Page 26: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

Your Turn

Get in groups & work on following activity

Page 27: CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

For Next Lecture

Read sections 7.1, 9.8 for Friday What is the boolean data type? How do the boolean operations work? How do C++ functions return boolean

values?

Week #3 weekly assignment due Tuesday Problems available via Angel If problem takes more than 10 minutes,

TALK TO ME!