COMP 202 Lecture Notes - Lecture 1: Programming Language, Binary Number, Bytecode

12 views5 pages
COMP 202: Introduction to Programming
Lecture 1: Introduction to Programming
Algorithms: a set of well-define and ordered instructions for solving a problem in a finite
number of steps
- “well-defined” and “ordered” - we have to be clear and particular because computers
cannot make the same logical jumps that we do, they can’t assume context
- “finite” – if infinite, no solution, they also have to be consecutive steps
______________________________________________________________________________
Example: Counting the number of apples in a basket
- Humans would be able to do this with ease using perception/cognition, because we have
evolved to be able to at least estimate amounts based off of very little information
- Computer would have to use as many resources as possible in this case, we can create a
second basket for the computer to use and log how many apples there are using a counter.
______________________________________________________________________________
Programming: the process of creating an algorithm that tells a computer how to perform a task
- Given a task, thinking of a solution
- Designing an algorithm with precise instructions
- Translating these instructions into a language that the computer can understand (coding,
implementation)
- Then check to see if correct (testing), and fixing any problems (debugging)
Program: sequence of instructions that consist of:
- Input
- Output
- Mathematical operation
- Testing
- Repetition
- Basket with apples
- Number of apples
- Counter = Counter + 1
- If Basket-A is empty
- Repeat until Basket-A is empty
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
COMP 202: Introduction to Programming
Data Representation in Computers:
Computers are computational devices and can only understand numbers, HOWEVER, natural language
obviously does not consist solely of numbers!
All information stored in computers is stored as numbers.
- Text as Numbers
o Computer stores the numerical representation of each letter
- Images as Numbers
o Bitmap: each pixel is made up of 3 colour channels (R, G, B) that each have a value between 0-
255; computers store a numerical representation of each pixel
- Music as Numbers
o WAV format: stores the amplitude of a sound wave over time; the sound wave is the sum of
fundamental frequencies that make up what you hear
- Data as Numbers
o Obviously data can take the form of numbers, but these are not represented by the regular
decimal system we use, but by binary
Decimal and Binary:
Decimal:
- 10 possible digits (from 0 to 9), Base = 10
o So to represent the year 2017,
2, 0, 1, 7
2017 = 2 x  + 0 x  + 1 x  + 7 x 
= 2000 + 0 + 10 + 7
Binary:
- 2 possible digits (from 0 to 1), Base = 2
o So for 1101010
1, 1, 0, 1, 0, 1, 0
1101010 = 1 x + 1 x + 0 x + 1 x + 0 x + 1 x + 0 x
= 106
Decimal to Decimal:
What is 536710 in decimal notation (base 10)?

 = 536R7

 = 53R6

 = 5R3
 = 0R5
Decimal to Binary:
What is 5310 in binary notation (base 2)?

= 26R1

= 13R0

= 6R1
= 3R0
= 1R1
= 0R1
Taking the remainders from the bottom to the top,
we get the answer = 5367
As a general rule, if the number is odd, R = 1, if even, R = 0
Continue dividing until the quotient is 0, and the solution is
once again taking the remainders from top to bottom = 110101
This is called the remainder method
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
jc123 and 40170 others unlocked
COMP 202 Full Course Notes
100
COMP 202 Full Course Notes
Verified Note
100 documents

Document Summary

Algorithms: a set of well-define and ordered instructions for solving a problem in a finite number of steps. Well-defined and ordered - we have to be clear and particular because computers cannot make the same logical jumps that we do, they can"t assume context. Finite if infinite, no solution, they also have to be consecutive steps. Example: counting the number of apples in a basket. Humans would be able to do this with ease using perception/cognition, because we have evolved to be able to at least estimate amounts based off of very little information. Computer would have to use as many resources as possible in this case, we can create a second basket for the computer to use and log how many apples there are using a counter. Programming: the process of creating an algorithm that tells a computer how to perform a task. Given a task, thinking of a solution.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents