review binary –each digit place is a power of 2 –any two state phenomenon can encode a binary...
Post on 20-Dec-2015
217 views
TRANSCRIPT
Review
• Binary– Each digit place is a power of 2– Any two state phenomenon can encode a binary
number– The number of bits (digits) required directly
relates to the amount of physical resource required
– Bit, Byte, 1K, 1Meg
Review
• Integers – Simple whole numbers
– How many bits required to contain an integer• The power of 2 just larger than that integer
• Floating point– Numbers with decimal points
– Numbers with exponents
– Can represent very large and very small numbers
Review
• Numeric expressions (+ - * /)1+2
3*4 + 7
6.2/(4.2-2.2)
• Boolean (true, false) (<, >, <=, >=, ==, !=)1 > 2
(3*5) <= 17
Review
• Characters– Every character corresponds to a unique
number– Sorting order– ASCII - encodes all American English
characters (1 byte)– UNICODE encodes all commercially used
characters in the world (2 bytes)
Programs
• Variables
• Assignment
• Sequences of instructions
Variables
• A named place to store a value
• AssignmentGeorge = 32;
Size = 17;
Weight = 120;
George 32Size 17Weight 120
Program
• A sequence of things to do
A = 75;
B = A+13;
A = A-B+3;
C = A/2 + 1;
Program
• A sequence of things to do
A = 75;
B = A+13;
A = A-B+3;
C = A/2 + 1;
A 75B ?C ?
Program
• A sequence of things to do
A = 75;
B = A+13;
A = A-B+3;
C = A/2 + 1;
A 75B 88C ?
A + 13
75 + 13 = 88
Program
• A sequence of things to do
A = 75;
B = A+13;
A = A-B+3;
C = A/2 + 1;
A -10B 88C ?
A-B+3
75 - 88 + 3 = -10
Program
• A sequence of things to do
A = 75;
B = A+13;
A = A-B+3;
C = A/2 + 1;
A -10B 88C -4
A / 2 + 1
-10 / 2 + 1 = -4
Program Quiz
• Do each in sequence
Fred = 2*7;
Jane = 16;
Fred = Jane - Fred;
Jane = Fred/2;
Fred ?Jane ?
Program Quiz
• Do each in sequence
Fred = 2*7;
Jane = 16;
Fred = Jane - Fred;
Jane = Fred/2;
Fred 14Jane ?
Program Quiz
• Do each in sequence
Fred = 2*7;
Jane = 16;
Fred = Jane - Fred;
Jane = Fred/2;
Fred 14Jane 16
Program Quiz
• Do each in sequence
Fred = 2*7;
Jane = 16;
Fred = Jane - Fred;
Jane = Fred/2;
Fred 14Jane 16
Jane - Fred16 - 142
Program Quiz
• Do each in sequence
Fred = 2*7;
Jane = 16;
Fred = Jane - Fred;
Jane = Fred/2;
Fred 2Jane 16
Jane - Fred16 - 142
Program Quiz
• Do each in sequence
Fred = 2*7;
Jane = 16;
Fred = Jane - Fred;
Jane = Fred/2;
Fred 2Jane 1
Arrays
• Access by Index
0 ?1 ?2 ?3 ?4 ?
A
0 ?1 ?2 ?
B
Arrays
• Access by Index
A[0] = 7;
B[1] = 4;
B[2] = A[0]+1;
A[1] = B[2]/2;
A[3] = 7-B[1];
0 ?1 ?2 ?3 ?4 ?
A
0 ?1 ?2 ?
B
Arrays
• Access by Index
A[0] = 7;
B[1] = 4;
B[2] = A[0]+1;
A[1] = B[2]/2;
A[3] = 7-B[1];
0 71 ?2 ?3 ?4 ?
A
0 ?1 ?2 ?
B
Arrays
• Access by Index
A[0] = 7;
B[1] = 4;
B[2] = A[0]+1;
A[1] = B[2]/2;
A[3] = 7-B[1];
0 71 ?2 ?3 ?4 ?
A
0 ?1 42 ?
B
Arrays
• Access by Index
A[0] = 7;
B[1] = 4;
B[2] = A[0]+1;
A[1] = B[2]/2;
A[3] = 7-B[1];
0 71 ?2 ?3 ?4 ?
A
0 ?1 42 8
B
Arrays
• Access by Index
A[0] = 7;
B[1] = 4;
B[2] = A[0]+1;
A[1] = B[2]/2;
A[3] = 7-B[1];
0 71 42 ?3 ?4 ?
A
0 ?1 42 8
B
Arrays
• Access by Index
A[0] = 7;
B[1] = 4;
B[2] = A[0]+1;
A[1] = B[2]/2;
A[3] = 7-B[1];
0 71 42 ?3 34 ?
A
0 ?1 42 8
B
Strings
• An array of Characters
A=“Lloyd”;
B= “Big”;
B[2] = A[0]+1;
A B0 76 L1 108 l2 111 o3 121 y4 100 d
0 ?1 ?2 ?
Strings
• An array of Characters
A=“Lloyd”;
B= “Big”;
B[2] = A[0]+1;
A B0 76 L1 108 l2 111 o3 121 y4 100 d
0 66 B1 105 i2 103 g
Strings
• An array of Characters
A=“Lloyd”;
B= “Big”;
B[2] = A[0]+1;
A B0 76 L1 108 l2 111 o3 121 y4 100 d
0 66 B1 105 i2 77 M
Strings
• How do you put “ in a string?
• Special characters preceded by \
A=“Lloyd”;
B= “Big”;
B[2] = A[0]+1;
B = “\”P\\”
A B0 76 L1 108 l2 111 o3 121 y4 100 d
0 34 "1 80 P2 92 \
Sound• Each time samples the volume (amplitude)• Sound = array of volume values
0 1 2 3 4 5 6 7 8 9 10-10 -5 10 20 10 -7 -15 -20 -12 4 8
2D-Arrays
Rows
Columns
[Rows-1,Columns-1]
[0,0]
# of elements = Rows * Columns
5
10
[4,9]5 * 10 = 50
Images - 2D array of values
• Image [x,y]