Boolean Logic, Algorithms, Programs, and Basic Scratch Programming Boolean Logic ULM/HHIM Summer Program Project 3, Day 4, Part 1 6/8/2011 Paul D. Wiedemeier, Ph.D. 1 6/8/2011 Boolean Logic • AND, OR, and XOR are binary Boolean operators. • NOT is a unary Boolean operator. • When searching computer databases, including keyword searching of the online catalog, these sets are controlled by use of Boolean operators AND, OR, XOR, and NOT. Paul D. Wiedemeier, Ph.D. 2 Boolean Logic • The principle of Boolean logic lets you organize concepts together in sets. 6/8/2011 Paul D. Wiedemeier, Ph.D. Operator Result ----------------------------bit AND bit bit bit OR bit bit bit XOR bit bit NOT bit bit • All operate on binary number(s), based on bit position, or two bits. 3 6/8/2011 Boolean Logic Paul D. Wiedemeier, Ph.D. 4 Boolean Logic • An AND Boolean operator requires two inputs • AND truth table – Inputs are also called operands. • Outputs ‘True’ or ‘1’ if and only if both inputs are ‘True’ or ‘1’ • AND graphic symbol – “AND gate” 6/8/2011 Paul D. Wiedemeier, Ph.D. 5 6/8/2011 Paul D. Wiedemeier, Ph.D. 6 1 Boolean Logic Boolean Logic • An OR Boolean operator requires two inputs. • OR truth table • Outputs ‘True’ or ‘1’ if any one or both inputs are ‘True’ or ‘1’. • OR graphic symbol – “OR gate” 6/8/2011 Paul D. Wiedemeier, Ph.D. 7 6/8/2011 Paul D. Wiedemeier, Ph.D. 8 Boolean Logic Boolean Logic • An Exclusive OR (XOR) Boolean operator requires two inputs. • XOR truth table x y x XOR y ---------------------0 0 0 0 1 1 1 0 1 1 1 0 • Outputs ‘True’ or ‘1’ if only one of the inputs is ‘True’ or ‘1’. – One input is ‘True’, or the other input is ‘True’, but both are not ‘True’ • XOR graphic symbol – “XOR gate” • Symbolized by circle plus sign: x ⊕ y 6/8/2011 Paul D. Wiedemeier, Ph.D. 9 6/8/2011 Boolean Logic Paul D. Wiedemeier, Ph.D. 10 Boolean Logic • • A NOT Boolean operator requires a single input. NOT truth table – Input combinations on the left • Inverts the value of the input. – Output of function on the right • • Symbolized by a tic or overbar: x’, x NOT graphic symbol – “NOT gate” – Triangle with little circle indicates inversion 6/8/2011 Paul D. Wiedemeier, Ph.D. 11 6/8/2011 Paul D. Wiedemeier, Ph.D. 12 2 http://en.wikipedia.org/wiki/Algorithm Algorithms • In mathematics, computer science, and related subjects, an algorithm is an effective method for solving a problem expressed as a finite sequence of instructions. Algorithms 6/8/2011 Paul D. Wiedemeier, Ph.D. 13 6/8/2011 Algorithms • Algorithms are similar to blueprints. – Architects create blue prints, which are used by construction worker to erect buildings. – System analysts create algorithms, which are used by computer programmers to create programs. • How the instructions are arranged and the order in which they occur defines a computer programs semantics. Paul D. Wiedemeier, Ph.D. 14 Algorithms • Algorithms are comprised of several human readable instructions, called pseudo code, that describe the execution of a computer program. 6/8/2011 Paul D. Wiedemeier, Ph.D. 15 6/8/2011 Paul D. Wiedemeier, Ph.D. 16 Programming Exercise 1 • Read the directions for Programming Exercise 1, which you will find in your folder. 6/8/2011 Paul D. Wiedemeier, Ph.D. Programs 17 6/8/2011 Paul D. Wiedemeier, Ph.D. 18 3 Programs • Though programs are constructed from algorithms, they are written using a specific programming language. – The human readable instructions are converted into the instructions from a programming language. 6/8/2011 Paul D. Wiedemeier, Ph.D. LISP: (print “Hello World”) Java: System.out.print(“Hello World”); FORTRAN: WRITE (6,7) 7 FORMAT(13H HELLO, WORLD) Pascal: writeln('Hello World'); C: print(“Hello World”) Scratch: 19 6/8/2011 Programs Paul D. Wiedemeier, Ph.D. 20 Programs • Basic program operation • The specific instructions within a programming language defines the syntax of a program. – Obtain input from the user, or from a file, or from both. • Verify that the input is valid. • Today, there literally hundreds of programming languages available for use. – Process the input to create output. • Use the correct programming language to solve the problem at hand. 6/8/2011 Paul D. Wiedemeier, Ph.D. – Display the output to the computer's screen and/or store the output in a file. 21 6/8/2011 Programs Paul D. Wiedemeier, Ph.D. 22 Programs • All programs can be constructed from one of three types instructions • Examples of sequential instructions – Capturing input from the user – Displaying output to the computer screen – Assigning a value to a variable – Performing a mathematical computation – Sequential instructions – Selection instructions – Repetition instructions (i.e. loops) 6/8/2011 Paul D. Wiedemeier, Ph.D. 23 6/8/2011 Paul D. Wiedemeier, Ph.D. 24 4 Programs Programs • Examples of selection instructions • Examples of repetition instructions – If (some condition is true), then – While (some condition is true) • execute some instructions. Pre-Test Loop • Execute some instructions. – If (some condition is true), then – Execute some instructions • execute some instructions, • While (some condition is true) Post-Test Loop – else 6/8/2011 • execute some Paul other instructions. D. Wiedemeier, Ph.D. 25 6/8/2011 Paul D. Wiedemeier, Ph.D. 26 Programs • Examples of repetition instructions Basic Scratch Programming – Execution of some instructions Post-Test Loop • Until (some condition is false) 6/8/2011 Paul D. Wiedemeier, Ph.D. 27 6/8/2011 Basic Scratch Programming Paul D. Wiedemeier, Ph.D. Basic Scratch Programming • Scratch is a fairly new programming language developed by the Lifelong Kindergarten Group at the MIT Media Lab. • Locate the Scratch icon on your computer’s desktop. • What makes it unique from older languages is that it is graphical. • Double click the Scratch icon to execute the Scratch project development environment. – The program instructions look like Lego blocks and you “snap” them together in a particular sequence to create a program. 6/8/2011 Paul D. Wiedemeier, Ph.D. 28 29 6/8/2011 Paul D. Wiedemeier, Ph.D. 30 5 File Save File Open Green Flag Program Execute Programming Exercise 2 Different Instructions Stage • Read the directions for Programming Exercise 2, which you will find in your folder. Sprite Blocks Pallete Script Area Sprite List 6/8/2011 Paul D. Wiedemeier, Ph.D. 31 6/8/2011 Programming Exercise 3 Paul D. Wiedemeier, Ph.D. 32 Programming Exercise 4 • Read the directions for Programming Exercise 3, which you will find in your folder. 6/8/2011 Paul D. Wiedemeier, Ph.D. • Read the directions for Programming Exercise 4, which you will find in your folder. 33 6/8/2011 Paul D. Wiedemeier, Ph.D. 34 6
© Copyright 2025 Paperzz