Top Banner
LECTURE 8: COMPUTERS AS STORAGE PHY 107 – Programming For Science
27

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

Jan 17, 2016

Download

Documents

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: PHY 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.

LECTURE 8:COMPUTERS AS STORAGE

PHY 107 – Programming For Science

Page 2: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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 PS4 can play Bloodborne 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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: PHY 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 pages 91 – 98 for Monday What is the boolean data type? How do the boolean operations work? What happens when we execute an if

statement

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

TALK TO ME!