570 likes | 633 Vues
Introduction to Binary. Why Bother with Binary?. This is all about electronics We don’t use binary because electronics do We designed electronics to use binary because it is very easy to do so Trying to use decimal inside electronics would be crazy difficult. Why Bother with Binary?.
E N D
Why Bother with Binary? This is all about electronics We don’t use binary because electronics do We designed electronics to use binary because it is very easy to do so Trying to use decimal inside electronics would be crazy difficult
Why Bother with Binary? Operations are easy in electronics (just wait!) Binary numbers can be used to represent anything
Why Bother with Binary? Operations are easy in electronics (just wait!) Binary numbers can be used to represent anything Numbers!
Why Bother with Binary? Operations are easy in electronics (just wait!) Binary numbers can be used to represent anything Numbers! π = 3.1415926535 [and more!]
Why Bother with Binary? Operations are easy in electronics (just wait!) Binary numbers can be used to represent anything Numbers! π = 3.1415926535 [and more!] Words “To be, or not to be!” Pictures Videos
Why Bother with Binary? Operations are easy in electronics (just wait!) Binary numbers can be used to represent anything Numbers! π = 3.1415926535 [and more!] Words “To be, or not to be!” Pictures Videos Programs (like games!)
Number Systems Ways to organize and write numbers Set of digits Set of operations Addition Subtraction
Number Systems – Decimal Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Operations Addition ( 3 + 5 ) Subtraction ( 5 – 3 )
Number Systems – Decimal Written Form Every “place” is 10 times the place to the right
Number Systems – Decimal What’s going on, here? 1000 * 5 + 100 * 2 + 10 * 8 + 1 * 1 = 5281
Number Systems – Binary Digits 0, 1 Operations Addition ( 011 + 101 ) Subtraction ( 101 – 011 ) Fun new things (and, or, not, xor)
Number Systems – Binary States can be easily represented in electronics Off False 0 On True 1
Number System - Binary Written Form Every “place” is twice the place to the right
Number Systems – Binary Same number as before 1000000000000 + 0010000000000 + 0000010000000 + 0000000100000 + 0000000000001 = 1010010100001
Familiar Numbers Decimal: 25 10 * 2 + 1 * 5 25 Binary: 11001 10000 + 01000 + 00001 11001
Binary Numbers Just another way to “write” the numbers you see every day
Numbers with Meaning How do we represent words in computers?
Numbers with Meaning How do we represent words in computers? Numbers!
Numbers with Meaning How do we represent words in computers? Numbers! (Bet you didn’t see what one coming...)
ASCII American Standard Code for Information Interchange A special set of numbers to represent letters All letters have a number assigned to them
Making Words From Letters How do we write our ABCs?
Making Words From Letters How do we write our ABCs? Like this: □■□□□□□■□■□□□□■□□■□□□□■■
Making Words From Letters How do we write our ABCs? Like this: □■□□□□□■□■□□□□■□□■□□□□■■ How about XYZ?
Making Words From Letters How do we write our ABCs? Like this: □■□□□□□■□■□□□□■□□■□□□□■■ How about XYZ? Like this: □■□■■□□□□■□■■□□■□■□■■□■□
Bonus Can you decode the binary code on my shirt?
Arithmetic in Binary Easy You only need to know how to add 0 and 1 Hardest operation you ever have to do is 1 + 1 Hint: the answer isn’t “2”
Addition – Decimal 2 + 2 = 2 + 8 = 7 + 8 =
Addition – Binary 0 + 0 = 0 + 1 = 1 + 0 = 1 + 1 =
Addition – Binary 10 + 10 = ( 2 + 2 ) 10 + 1000 = ( 2 + 8 ) 111 + 1000 = ( 7 + 8 ) 10110 + 01011 = ( 22 + 11 )
Funny Operators And 0 ∧ 0 = 0 0 ∧ 1 = 0 1 ∧ 0 = 0 1 ∧ 1 = 1 Or
Programs in Binary Everything in a computer is represented with binary numbers Programs in a computer are (of course!) represented in binary numbers
Programs in Binary Instructions List of things you can do Program List of instructions, in order Storage Instructions, encoded into binary, in the computer’s memory
Programs in Binary - Instructions Human Robots Just like our first week in Coding Club Can move forward Can turn right Can turn left
Programs in Binary Program Move forward Move forward Turn left Move forward Turn right Move forward etc.
Programs in Binary Instructions .. in binary! We have 3 instructions We will need two “bits” for each instruction 2 bits can represent 0, 1, 2, or 3 in decimal We only need 3 of these 4; one of them will be unused
Programs in Binary Instructions .. in binary! Turn left: 01 Turn right: 10 Move forward: 11
Programs in Binary Program Move forward Move forward Turn left Move forward Turn right Move forward etc. Instructions 11 11 01 11 10 11 etc.
Programs in Binary Program in computer memory 111101111011 or ■■■■□■■■■□■■
How Does a Computer Run a Program? Program is in memory ■■■■□■■■■□■■ Computer knows all instructions are 2-bits wide Computer starts at the beginning Read 2 bits Decide which instruction is represented Perform instruction (e.g. turn, move) Repeat
Complicated Programs Human Robots Limited to turn, move Real Computer Programs Can do much more
Complicated Programs Perform arithmetic Make decisions Run loops Load/store information
Complicated Programs Require lots of instructions Examples: load, store add, subtract compare jump!
Complicated Programs Instructions Load Add Jump Jump-if-equal Instructions 0001 0011 0101 0110
Complicated Programs • Instructions • Load • Add • Jump • Jump-if-equal • Instructions • 0001 • 0011 • 0101 • 0110 • Extra • What? • What? • Where? • What/Where?
Let’s Count to Ten • Instructions • Load • Add • Jump • Jump-if-equal • Instructions • 0001 • 0011 • 0101 • 0110 • Extra • 0000 • 0001 • 0101 • 1010
Let’s Count to Ten • Instructions • Load • Add • Jump • Jump-if-equal • Instructions • 0001 • 0011 • 0101 • 0110 • Extra • 0000 • 0001 • 0101 • 1010 0001 0000 0011 0001 0110 1010 0101 0101 0101