PHY 107 – Programming For Science
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, Numbers & arithmetic easy to understand Subtracting roman numerals is not for faint-of-heart
Positional Notation for = 2 ones= 2 * 1 =2
Positional Notation for = 2 ones= 2 * 1 =2 6= 6 tens= 6 * 10 =60
Positional Notation for = 2 ones= 2 * 1 =2 6= 6 tens= 6 * 10 =60 8= 8 hundreds= 8 * 100 =800
Positional Notation for = 2 ones= 2 * 1 =2 6= 6 tens= 6 * 10 =60 8= 8 hundreds= 8 * 100 =800 5= 5 thousands= 5 * 1000 =5000
Positional Notation for = 2 ones= 2 * 1 =2 6= 6 tens= 6 * 10 =60 8= 8 hundreds= 8 * 100 =800 5= 5 thousands= 5 * 1000 =
Decimal Positional Notation Formal equation for a number d n...d 3 d 2 d 1 d 0 d 0 is digit in ones place, d 1 is in tens place, … d 0 * 10 0 d 1 * 10 1 d 2 * 10 2 d 3 * 10 3 … + d n * 10 n
Base-10 Positional Notation d0d0 2= 2 ones= 2 * 1 =2 d1d1 6= 6 tens= 6 * 10 =60 d2d2 8= 8 hundreds= 8 * 100 =800 d3d3 5= 5 thousands= 5 * 1000 =
Base-10 Positional Notation d0d0 2= 2 ones= 2 * 10 0 =2 d1d1 6= 6 tens= 6 * 10 1 =60 d2d2 8= 8 hundreds= 8 * 10 2 =800 d3d3 5= 5 thousands= 5 * 10 3 =
Base-10 Positional Notation 0d00d0 2= 2 ones 0 = 2 * 10 0 =2 1d11d1 6= 6 tens 1 = 6 * 10 1 =60 2d22d2 8= 8 hundreds 2 = 8 * 10 2 =800 3d33d3 5= 5 thousands 3 = 5 * 10 3 =
Base-10 Positional Notation d0d0 2= 2 ones= 2 * 10 0 =2 d1d1 6= 6 tens= 6 * 10 1 =60 d2d2 8= 8 hundreds= 8 * 10 2 =800 d3d3 5= 5 thousands= 5 * 10 3 =
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
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 A 16 = D 16 = B 16 = E 16 = C 16 = F 16 = 15 10
Positional Notation To convert d n... d 3 d 2 d 1 d 0 into decimal: From base-10 d 0 * 10 0 d 1 * 10 1 d 2 * 10 2 d 3 * 10 3 … + d n * 10 n
Positional Notation To convert d n... d 3 d 2 d 1 d 0 into decimal: From base-b d 0 * b 0 d 1 * b 1 d 2 * b 2 d 3 * b 3 … + d n * b n
Converting Binary to Decimal = d0d0 d1d1 d2d2 d3d3 d4d4 d5d5
Converting Binary to Decimal = d0d0 1* d1d1 1* d2d2 0* d3d3 1* d4d4 0* d5d5 1*
Converting Binary to Decimal = d0d0 1* 2 0 = d1d1 1* 2 1 = d2d2 0* 2 2 = d3d3 1* 2 3 = d4d4 0* 2 4 = d5d5 1* 2 5 =
Converting Hex to Decimal = d0d0 d1d1 3F 16 = d0d0 d1d1
Converting Hex to Decimal = d0d = 7 10 d1d = F 16 = d0d0 F 16 =15 10 d1d = 3 10
Converting Hex to Decimal = d0d = 7 10 * 16 0 = d1d = 2 10 * 16 1 = 3F 16 = d0d0 F 16 =15 10 * 16 0 = d1d = 3 10 * 16 1 =
Positional Notation Review To convert d n... d 3 d 2 d 1 d 0 into decimal: From base-b d 0 * b 0 d 1 * b 1 d 2 * b 2 d 3 * b 3 … + d n * b n
Converting Decimal To Binary Converting from decimal to binary (base-2): While decimal number ≠ 0 Divide decimal number by 2 Move remainder to left end of answer Replace decimal number with quotient =
Converting Decimal To Base-b More generally, convert from decimal to base-b: While decimal number ≠ 0 Divide decimal number by b Move remainder to left end of answer Replace decimal number with quotient = 16
Your Turn Get in groups & work on following activity
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!