You are on page 1of 38

Introduction Computers and Binary Scratch and Basic Programming

COMP-202 Week 1

Melanie Lyman-Abramovitch

September 3rd, 2014

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Admin

1. Syllabus
2. Office for Students with Disabilities (OSD)
http://www.mcgill.ca/osd/contact

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Who are you?

Figure : Percentage of Students in Computer Science and Engineering

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

What is Computer Programming?

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

What is Computer Programming?

I Computer programming (often shortened to programming) is


a process that leads from an original formulation of a
computing problem to executable programs.
http://en.wikipedia.org/wiki/Computer programming

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

What is Computer Programming?

I Computer programming (often shortened to programming) is


a process that leads from an original formulation of a
computing problem to executable programs.
http://en.wikipedia.org/wiki/Computer programming

I Computer programming is the craft of writing useful,


maintainable, and extensible source code which can be
interpreted or compiled by a computing system to perform a
meaningful task. http://en.wikibooks.org/wiki/Computer Programming

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

What is a Computer Program?

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

What is a Computer Program?

I A computer program, or just a program, is a sequence of


instructions, written to perform a specified task with a
computer. http://en.wikipedia.org/wiki/Computer program

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

What is Computer Science?

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

What is Computer Science?


I Computer science is the scientific and practical approach to
computation and its applications. It is the systematic study of
the feasibility, structure, expression, and mechanization of the
methodical procedures (or algorithms) that underlie the
acquisition, representation, processing, storage,
communication of, and access to information, whether such
information is encoded as bits in a computer memory or
transcribed in genes and protein structures in a biological cell.
http://en.wikipedia.org/wiki/Computer science

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

What is Computer Science?


I Computer science is the scientific and practical approach to
computation and its applications. It is the systematic study of
the feasibility, structure, expression, and mechanization of the
methodical procedures (or algorithms) that underlie the
acquisition, representation, processing, storage,
communication of, and access to information, whether such
information is encoded as bits in a computer memory or
transcribed in genes and protein structures in a biological cell.
http://en.wikipedia.org/wiki/Computer science

I Computer science is the study of how to manipulate, manage,


transform and encode information.
http://simple.wikipedia.org/wiki/Computer science

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

How Does a Computer Work?

Binary:
I off = 0
I on = 1

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Base 10 - Decimal

I 5 = 5 × 100

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Base 10 - Decimal

I 5 = 5 × 100
I 25 = 2 × 101 + 5 × 100

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Base 10 - Decimal

I 5 = 5 × 100
I 25 = 2 × 101 + 5 × 100
I 425 = 4 × 102 + 2 × 101 + 5 × 100

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Base 10 - Decimal

I 5 = 5 × 100
I 25 = 2 × 101 + 5 × 100
I 425 = 4 × 102 + 2 × 101 + 5 × 100
I 3425 = 3 × 103 + 4 × 102 + 2 × 101 + 5 × 100

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Base 2 - Binary

I 0 = 0 × 20

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Base 2 - Binary

I 0 = 0 × 20
I 10 = 1 × 21 + 0 × 20

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Base 2 - Binary

I 0 = 0 × 20
I 10 = 1 × 21 + 0 × 20
I 110 = 1 × 22 + 1 × 21 + 0 × 20

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Base 2 - Binary

I 0 = 0 × 20
I 10 = 1 × 21 + 0 × 20
I 110 = 1 × 22 + 1 × 21 + 0 × 20
I 1110 = 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Base 2 - Binary

I 0 = 0 × 20
I 10 = 1 × 21 + 0 × 20
I 110 = 1 × 22 + 1 × 21 + 0 × 20
I 1110 = 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20
I 01110 = 0 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Base 2 - Binary

I 0 = 0 × 20
I 10 = 1 × 21 + 0 × 20
I 110 = 1 × 22 + 1 × 21 + 0 × 20
I 1110 = 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20
I 01110 = 0 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20
I 101110 = 1 × 25 + 0 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Binary to Decimal

What is 101110?2 in decimal notation (base 10)?

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Binary to Decimal

What is 101110?2 in decimal notation (base 10)?


I 1011102 = 1 × 25 + 0 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Binary to Decimal

What is 101110?2 in decimal notation (base 10)?


I 1011102 = 1 × 25 + 0 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20
I 1011102 = 25 + 0 + 23 + 22 + 21 + 0

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Binary to Decimal

What is 101110?2 in decimal notation (base 10)?


I 1011102 = 1 × 25 + 0 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20
I 1011102 = 25 + 0 + 23 + 22 + 21 + 0
I 1011102 = 32 + 0 + 8 + 4 + 2 + 0

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Binary to Decimal

What is 101110?2 in decimal notation (base 10)?


I 1011102 = 1 × 25 + 0 × 24 + 1 × 23 + 1 × 22 + 1 × 21 + 0 × 20
I 1011102 = 25 + 0 + 23 + 22 + 21 + 0
I 1011102 = 32 + 0 + 8 + 4 + 2 + 0
I 1011102 = 4610

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Decimal to Binary

What is 5310 in binary notation (base 2)?

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Decimal to Binary

What is 5310 in binary notation (base 2)?


I 53 = 26R1
2

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Decimal to Binary

What is 5310 in binary notation (base 2)?


I 53 = 26R1
2
I 26 = 13R0
2

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Decimal to Binary

What is 5310 in binary notation (base 2)?


I 53 = 26R1
2
I 26 = 13R0
2
I 13 = 6R1
2

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Decimal to Binary

What is 5310 in binary notation (base 2)?


I 53 = 26R1
2
I 26 = 13R0
2
I 13 = 6R1
2
I 6 = 3R0
2

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Decimal to Binary

What is 5310 in binary notation (base 2)?


I 53 = 26R1
2
I 26 = 13R0
2
I 13 = 6R1
2
I 6 = 3R0
2
I 3 = 1R1
2

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Decimal to Binary

What is 5310 in binary notation (base 2)?


I 53 = 26R1
2
I 26 = 13R0
2
I 13 = 6R1
2
I 6 = 3R0
2
I 3 = 1R1
2
I 1 = 0R1
2

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Decimal to Binary

What is 5310 in binary notation (base 2)?


I 53 = 26R 1
2
I 26 = 13R 0
2
13
2 = 6R 1
I

I 6 = 3R 0
2
I 3 = 1R 1
2
I 1 = 0R 1
2
I 5310 = 110101

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

Decimal to Binary - Explained

Each digit in binary is basically an odd/even check. In the previous


example, we first check if 53 is odd or even. 53 is odd, so we get a
1 in the 20 place. Then, we take 53 2 (rounded down), which is 26,
and again check if its odd or even. 26 is even, so we get a 0 in the
21 place. This repeats, until we get 0 as a result of our integer
division, so we can stop.

COMP-202 Week 1
Introduction Computers and Binary Scratch and Basic Programming

ASCII
Char Dec. Bin Char Dec. Bin
A 65 0100 0001 N 78 0100 1110
B 66 0100 0010 O 79 0100 1111
C 67 0100 0011 P 80 0101 0000
D 68 0100 0100 Q 81 0101 0001
E 69 0100 0101 R 82 0101 0010
F 70 0100 0110 S 83 0101 0011
G 71 0100 0111 T 84 0101 0100
H 72 0100 1000 U 85 0101 0101
I 73 0100 1001 V 86 0101 0110
J 74 0100 1010 W 87 0101 0111
K 75 0100 1011 X 88 0101 1000
L 76 0100 1100 Y 89 0101 1001
M 77 0100 1101 Z 90 0101 1010
COMP-202 Week 1

You might also like