You are on page 1of 5

Week 0

How do we communication

CS 50 Binary System

4 2 1
0 0 0

1 = yes electricity
0 = no electricity

0 = 000
1 = 010
010 = 2 (2 + 0)
011 = 3 (2+1)
100 = 4 (4+0+0)
111 = 7 (4+2+1)
1000 = 8

1 byte = 8 bit
bit bit bit bit bit bit bit bit

Bit = binary digit

“The turning lightbulb on game”


to illustrate binary system

 don’t be afraid to practice very simple things with students


 call on students to participate
 include rewards (apple in this case)
 round of applause

128 64 32 16 8 4 2 1

50 = 32+16+2 = 00110010

Transistor  represent information and store values


If computer needs store information “50”, store information in transistor that way.
i.e. “light up bulbs accordingly”

 Take it up a level – hide the numbers


 ask for audience feedback
 round of applause

13 = 8+4+1 = 00001101

 Take it up a level – from numbers to letter


(We just need to agree what number equals the letter – becomes emails and letters)
World (who) decided that A = 65 (how?
Facts | Definitions

65 = 64 + 1 = 01000001

ASCII
“Just a fancy way of saying that”

H I !
72 73 33

Emojis also represented by numbers

Unicode (32 bits) = superset of ASCII

 Take it up a level – letter to emoji

Face with Tears of Joy = 128514

 Expand horizontally – Represent colors

RGB
How much Red, Green, Blue to use

72 73 33 = a shade of yellow
(instead of hi!)

 Take it up a level – multiple GIF – animated GIF

 Expand horizontally – Represent Music?


Loudness, length, etc.

Input = digits

Input algorithms  output (music, images, text, etc.)

Algorithm = step by step instructions for solving some problems.

 demonstrate how algorithm solve problem by flipping a phone book

Problem: Find Mike Smith in a phonebook


Flip page by page – slow
Flip two pages at onece – you might skip the name you need
(Fix – go back to Sm when you reach Sn)

How do you do it?


1. Go to the middle …M section
2. Remove A-M
3. Go to to the middle…T Section
4. Remove T-Z

This process only takes ten steps


1024
512
256
128
64
32
16
8
4
2
1 “Mike Smith”

A LOT quicker than page by page.

Pseudo Code
1 Pick up phone book
2 Open to the middle of phone book
3 Look at the page
4 If Smith is on page
5 Call Mike
6Else if Smith is earlier in book
7 Open to the middle of the left half of the book
8 Go back to line 3
9 Else if Smith is later in book
10 Open to the middle of the left half of the book
11 Go back to line 3
12 Else
13 Quit

Functions = actions that tell the computer what to do


If Else If = Conditions
Go back = Loop

Scratch MIT Lab

Scratch.mit.lab.edu

 Introduce bugs and ask students how to fix it

Broadcast event  communicate from one programme to another


show what is bad and how to improve it
“Marco Polo”
Copy and paste is bad code.

Better design:

Defining a function:

Week 1
Name this hello.c
Where to find the blocks (function)?  #include <stdio.h>
When flag clicked  int main(void)
Say Hello  {printf(“hello\n”);
}

(Characters or words = strings, which need “ “)


**finish your thought with ;

clang hello.c  turns source code into machine code (10101010)


a programme “a.out” is created
To Run the programme:
Use “./” i.e.  ./a.out
\n: moves down the $ sign when it is executed

To name the output: use “-o”  clang -o hello hello.c


 “hello” will appear instead of a.out

Commands:
ls  list out files in directory, and see which one can be executed e.g.
rm  remove files in directory e.g. rm a.out

Block What’s your name and wait  define name as “Answer”


Say hello NAME = printf(“hello,%s\n”, answer)
answer = get_string("What's your name?\n")
printf("hello,%s\n", answer);

%s = placeholder i.e. plug in variable that’s included after the comma


i.e. “hello, %s\n”, answer = hello, answer, where answer is the string defined before

You need to link block in the command line to make it work


 clang -o string name.c -lcs50

“-l” = link, cs50 = name of the directory to get the functions “string”
“combine my code and CS50’s code into a piece of programme that can run”

To get input from the programmer, use “get_string”;


To name this variable, use string answer =

“Make” = a programme that comes with mac, windows, linux, unix, etc.

Summary
Make = convert to machine code
./ = run

You might also like