Binary and Programming Basics

_Harvard CS50


Binary

Binary is represented as 0s and 1s, also known as bits. At a base level, Everything you see or do on a computer is using binary in some way, everything from text, to colour, to music is comprised of bits.

Below are some examples of numbers being represented in binary

Binary Number
0 0 1 One
0 1 0 Two
1 0 0 Three
1 0 1 Four
1 1 0 Five
1 1 1 Six

Text is translated to human readable format using the ASCII format, which stands for American Standard Code for Information Interchange.
ASCII takes binary and translates it into human readable characters, numbers, and symbols.

For example, the binary digit 41 on the ASCII Conversion Chart represents the Letter A
the binary digit 41 is comprised of the bits 01000001

Time Complexity

Time complexity is a way to measure the efficiency of an algorithm, it expresses how the time to solve a problem increases as the input size increases.

As shown on the Time Complexity chart below, there are 3 lines; n, n/2 and log^2n
You may also notice that none of these lines completely level of, this is because it is simply not possible to have an algorithm that will take the same amount of time no matter the amount of data inputted. we can however make this increase in Time to solve increase as little as possible over time.

As an example, if we were making a program to sort through a phone book, find a person and call them; we could turn and scan each page in the phone book until we find who we're looking for.
This will work for a small phone book, but if we have a large phone book with thousands or even hundreds of thousands of pages, this will drastically take longer. This would be represented as "n" on the chart above.

Another method to doing this would be to scan every two pages until we find who we're looking for, and turn back a page if we believe we have gone too far. While this is certainly faster than the first option, it will still drastically slow down as the number of pages increases. This would be represented as n/2 on the chart above

The final method is to open the phone book from the middle, decide if the person we are looking for is on the left or right from where we are and discard the pages where the person is not. keep repeating this until we are only left with one page, and scan that final page. This is represented as log^2n on the chart above.

Modern Day Programming

In the modern day, you are not likely to use binary to program a computer, instead we use programming languages such as C, Python, JavaScript, etc.

These languages are easy for both computers and humans to read. For example, here is the problem used above represented closer to modern day programming languages.

**pick up** phone book
**open to** middle of phone book
**look at page**
if person is on page
	**call** person
else if person is later in book
	**open to** middle of right half of book
	go back to line 3
else
	**quit**