150 likes | 161 Vues
Learn about Boolean algebra, logical operations, and circuit design, and practice programming through exercises and examples.
E N D
情報基礎BLecture 7 Takeshi TokuyamaTohoku University Graduate School of Information SciencesSystem Information SciencesDesign and Analysis of Information Systems
Computation • The world of {0, 1} • Boolean algebra • Logical operation • AND operation • 0 × 0 = 0 × 1 = 1 × 0 = 0, 1 × 1 = 1 • Series circuit • OR operation • 0 + 0 = 0, 0 + 1 = 1 + 0 = 1, 1 + 1 = 1 • Parallel circuit • NOT operation • NOT(0) = 1, NOT(1) = 0 NOT
Computation • AND operation • 0 × 0 = 0 × 1 = 1 × 0 = 0, 1 × 1 = 1 • Series circuit • Switching : relay, transistor, diode
Computation • OR operation • 0 + 0 = 0, 0 + 1 = 1 + 0 = 1, 1 + 1 = 1 • Parallel circuit
Computation • NOT operation • NOT(0) = 1, NOT(1) = 0 a electromanget NOT(a)
Example of Adder • Circuit to calculate a + b (a, b = 0 or 1) a b 0 + 0 = 00 1 + 0 = 01 0 + 1 = 01 1 + 1 = 10 NOT Upper Bit Lower Bit
Computation Model • AND, OR, NOT • Logical operation • Addition, subtraction, multiplication, division, comparison • IF • Programming model (decision tree model) • Addition, subtraction, multiplication, division, comparison • Load data from storage • Store data to storage • IF
Program and Decision Tree IF(B2>=90, “A”, IF(B2>=80, “B”, IF(B2>=70, “C”, IF(B2>=60, “D”,“F”)))) B2 True False A True False B True False C True False D F Computation proceeds through the tree
Loop • SUM(A2:A100) • Decision tree becomes deep • Loop structure • Loop management • When to stop? • In Excel… • By setting range A2:A100 Read a cell in column A Adder Temporal Result
Loop • Example: SUM(A2:A100) i=2 i = i + 1 TRUE Read A(i) i<100 Adder FALSE Temporal Result Output Temporal Result
Programming • Think about an algorithm • e.g. Grading procedure • Show a flowchart with decision tree and loop structure • Write the algorithm in programming language • Small vocabulary, easy
Programming • Make an operation which a computer work on • Algorithm designing • Logical work • Coding • Learning a programming language • Read programs • Make some change on programs • Debug(Error correction)
Programming hints • Learning programming language • Practice makes perfect • Follow examples • This is a pen > This is a dog • Follow good examples • Learn from the mistakes • This is a apple ?? • I is a man ?? • System will tell you mistakes • Guess what is wrong: logical mind and imagination
Exercise • Write a flowchart of program that acts same as COUNTIF(B2:B21, “A”) without using COUNTIF