Lesson One: Counting and Remembering Notes - rociorey/cci-2020 GitHub Wiki

What is Counting?

Counting is when you use groups of symbols to represent quantities or amounts. The most important thing to remember is that the graphic symbols we use to represent numbers are literally just that: symbols. The symbols do not inherently mean the numbers themselves. For example, the following symbols: 368, only mean the number three hundred and sixty-eight because someone said that 3 means three, 6 means six, and 8 means eight.

Decimal Vs. Unary Systems

Decimal (Base 10) Unary (Base One)
1 I
2 II
3 III
4 IIII
5 IIIII
6 IIIIII
7 IIIIIII

Decimal numbers require you to memorise 10 different symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. But they are very good at expressing large numbers. Unary only requires you to know one symbol: I. This makes it great for communication, but hard to use for larger numbers.

The Counting Principle Using Decimal Numbers:

It is often very important for us to count up to very high numbers. The decimal system is based on these 10 digits:

0, 1, 2 ,3, 4, 5, 6, 7, 8, 9

But once we get to 9, we can’t express any new number by using only one symbol. We need to change the symbol in some way to make sure other people know it means a different number. You can’t just say “the symbol 9 means nine” and then turn around and say “well no, in this context, the symbol 9 now means twenty-six”.

So what now? We add a symbol!

10, 12, 13…97, 98, 99

And again! Every time we have expressed all possible values with the amount of symbols we have, we add another symbol and the "places" go up.

100, 101, 102, 103, etc.

Counting with the Binary System

Binary is a number system which uses a base of 2 instead of 10, like the decimal system. It uses two symbols: circle and line, or 0 and 1 (off and on, nothing and something, ⃝ |)

DECIMAL BINARY NOTES FOR BINARY COUNTING
0 0
1 1 Ok, so here, we ran out of numbers, let’s add one.
2 10 Now we have 4 options: 00, 01, 10, 11. Two are discounted immediately: 00=0 and 01=1. Now we have to order the other two from smallest to largest.
3 11 Ok, so here, we ran out of numbers! Let’s add one.
4 100 8 options: 000, 001, 010, 011, 100, 101, 110, 111
5 101
6 110
7 111 Ok, so here, we ran out of numbers, let’s add one.
8 1000 16 options: 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010,1011, 1100, 1101, 1110, 1111
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111 Ok, so here, we ran out of numbers, let’s add one.
16 10000
17 10001
18 10010
19 10011
20 10100
21 10101
22 10110
23 10111
24 11000
25 11001
26 11010
27 11011
28 11100
29 11101
30 11110
31 11111 Ok, so here, we ran out of numbers! Let’s add one.
32 100000

Counting Tips:

Nothing Something is always less than Something Something.

100: Something Nothing Nothing

101: Something Nothing Something

110: Something Something Nothing

111: Something Something Something

Place Number:

Remember, WHERE the something appears is important: anything to the right adds value, just like in decimal

0001 = 1

001000 = 1,000

Logic Tip:

If you have four spaces and you have to make numbers in ascending order using only the symbols 1 and 0, which combinations of numbers can you make? How can you put them in ascending order?

0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010,1011, 1100, 1101, 1110, 1111

Binary Counting and Why it Matters

We add a symbol to decimal numbers every time we reach a new power of 10. Which ever power we are on is the amount of zeros we have. So 100 = 10^2, 1000 = 10^3, and so on.

Decimals Power of 10
10 10^1
100 10^2
1000 10^3
10000 10^4
100000 10^5
1000000 10^6
10000000 10^7
100000000 10^8
1000000000 10^9
10000000000 10^10

The system works exactly the same in binary. As soon as we have to add a number, we’ve reached a new power of two. But what those powers of two equal are super important for computing, because these numbers are the basic units of how we structure computer data. One of these units of two is called a “bit”

Binary Power of 2 Powers Equal Use in Computing
10 2^1 2 2 bits or Binary Digit
100 2^2 4 4 bits = 1 nibble
1,000 2^3 8 8 bits = 1 Byte
10,000 2^4 16
100,000 2^5 32
1,000,000 2^6 64
10,000,000 2^7 128
100,000,000 2^8 256
1,000,000,000 2^9 512
10,000,000,000 2^10 1,024 1,024 Bytes = 1 Kilobyte (KB)
100,000,000,000 2^11 2,048
1,000,000,000,000 2^12 4,096
10,000,000,000,000 2^13 8,192
100,000,000,000,000 2^14 16,384
1,000,000,000,000,000 2^15 32,768
10,000,000,000,000,000 2^16 65,536
100,000,000,000,000,000 2^17 131,072
1,000,000,000,000,000,000 2^18 262,144
10,000,000,000,000,000,000 2^19 524,288
100,000,000,000,000,000,000 2^20 1,048,576 1,048,576 Bytes = 1 Megabyte (MB)

Computers use binary to represent everything in memory. Binary is very well suited to computers because they work with electricity, so the easiest thing for them to work with is on and off switches. The two numbers in binary are just that: 1 and 0 or on and off.

Key Definitions:

Bit: Binary Digit

Byte: Eight Bits

Kilobyte: 1,024 (2^10) bytes

Megabyte: 1,048576 (2^20) bytes

Storing Data on Computers

We store data on our computers using data types. Data types are different ways of storing numbers and words in computers, which can either be stored as fixed values (constants) or values that can change (variables).

These are some different data types:

  • Whole numbers

    • Also called integers or ints.
    • 0,1,2,3,4 -6,9887
  • Numbers Between Integers

    • Called floating points or floats
    • 3.142 or -5.6857
  • Characters

    • Way you can store individual characters of the alphabet
    • Also called chars
    • Two systems:
      • ASCII – Used for English Latin alphabet system
      • Unicode - Broader system across languages and emojis
  • Strings

    • Ways to store words
    • Basically just a list of chars
    • Also called arrays
    • Strings are one dimensional arrays

Numbers have to be stored in certain amounts of memory. If these numbers get too big or negative or precise, the computer can run out of memory to store them, or overflow. Overflow is very, very bad.

Brief Introduction to Javascript

What is Javascipt?

Javascript is a programming language you can use to make web pages interactive. It first appeared in 1995, when its developer invented it in 10 days. You can create things like web applications, animations and VR with Javascript, and it is the most in-demand language for programmers

Using Javascript

Javascript is one of the three languages that make up the modern web: HTML, CSS, and Javascript

You can use Javascript directly within webpages, but also within <script> tags

The Javascript Console

How to get to it

Firefox - Browser -> Tools -> Web Console

Chrome – View -> Developer -> Javascript console

Can also use control or command i

What you can do with it

With the JavaScript Console, you can write and print commands. The code for this is Console.log, which prints your functions. Functions are a way to package a bunch of smaller commands within a larger command

Example of JavaScript Console, Strings, and Modifications:

During the lecture, Joel took us through some of the basic console.log and string functions, described below. He was also using the p5.js JavaScript basics site to do this, which explains all of the basic JavaScript commands.

Using console.log() and Variables

The first exercise was about using the console.log function and assigning variables.

Here, Joel showed us how he told the code to print out "hello, joel!" by writing

console.log("hello, joel!");

He then explained how to assign variables to mean specific things with the command

let x = 5;

And how you can do different maths operations with code, like

let y = x+7;

and then using the console.log() command to print out the answer: of x+7, which is 12

Building Operations and Strings

In this exercise, Joel taught us how to use console.log() to build more operations. Using numbers, he showed us how code builds on top of itself:

let x=5;

x = x + 1

6

x = x + 1

7

And how you can use console.log() to build the sentence "some text is here"

Printing Different Attributes (properties) of Strings

In these last two exercises, Joel explained how to use console.log() to print different attributes, or properties, of strings.

Here, Joel defined two sentences

let str = I like to eat pickles";

and

let funkystring = "I like to eat apples";

The reason the strings have different names is just so that the computer can tell them apart: they don't have any special significance. Joel then used these commands:

console.log(str.length);

The command for str.length gave him the exact amount of characters in the "I like to eat pickles" sentence. The second command is a bit trickier:

let pos = funkystring.indexOf("eat");

console.log(pos);

Joel first defined what he wanted the computer to find, the word "eat", and then asked the computer to find and print it with the console.log() command.

Important:

You CANNOT define two different things under the same variable

Basically, computers just remember things, and they change what they remember with different commands

All lines in javascript must end in a semicolon so the computer knows the line has ended

When something shows up as undefined, it means the system has logged it properly

End of Lecture Definitions:

Data Type = An attribute of data which tells the computer how to use that data. It also constrains the values that a variable or function might have, based on what the data type is.

Int = Short for integer. This is a data type that represents any whole number, and in a computer, it is often represented as binary digits, or bits

String = a sequence of characters (chars) which is considered to be a one-dimensional array. You can change strings with different modifiers in code.

Float = Also called a floating point number, these values have decimal points and are used to represent any number between integers (3.14, 2.98, etc.)

Array (list) = An array is a series of numbers or values, and can be used to implement other data structures, like lists and strings.

Vector = A dynamic kind of one-dimensional array. This data type is used to store or collect information and can be easily expanded.

Bool = Also called a Boolean. This data type can only have a true or false answer, and it usually used in conditional statements, which are statements that just ask for a true or false answer (for example, is the answer to x+1<3, yes or no)

Queue = A list of values that are held in a specific order, just like a real queue. This is used for values that need to be held in a specific place or things like names in sign up sheets, which are held in a specific order until they are processed. These also have no specific container amount, meaning they can be super long, super short, or have new items placed in front or behind them in the queue.

Char= Short for character. This data type stores a specific symbol, like a letter, and can be used in strings and other data types.

End of Lecture Number Videos:

The Powers of Ten A visual representation of distance, variables, and what it means to add a zero

How Big is Graham’s Number?: A visual description of Graham’s (really really really really really really really really) big number

Fun Facts!

What is the biggest number you can count to on your fingers?

641023

What about with your fingers and your toes?

Over 1,000,000

Resources

Full Lecture

Full Lecture Slides

Full List of Javascript Basics

⚠️ **GitHub.com Fallback** ⚠️