Lecture 02: Computational Literacy
Department of Quantitative Theory and Methods
Emory University
22 January, 2025
As we discussed in the first lecture, you will need to install the following software:
A terminal
Tip
Video: How to use an abacus
The first mechanical calculator capable of performing all four basic arithmetic operations (addition, subtraction, multiplication, and division)
Invented by Gottfried Wilhelm Leibniz in 1694
If you took a statistics course before the late 1970s, you likely used this type of mechanical calculator for your computations
The 1970s marked the transition from mechanical to electronic:
How do we convert money from dollars to coins? Assume we want to minimise the number of coins used
For example, what is $0.59 in coin representation? Use the same four-digit system: quarters, dimes, nickels, and pennies
$0.59 = 2 x $0.25 + 0 x $0.10 + 1 x $0.05 + 4 x $0.01 = c2014
Think-Pair-Share: do the following conversions
What is c1112 in dollars?
What is $0.61 in coin representation?
Solutions:
c1112 = $0.42 = 1 x $0.25 + 1 x $0.10 + 1 x $0.05 + 2 x $0.01
$0.61 = c2101 = 2 x $0.25 + 1 x $0.10 + 0 x $0.05 + 1 x $0.01
Now let us go back to computers! 💻
We can represent numbers using only 0s and 1s with the binary number system
Instead of counting the number of 1s, 5s, 10s, and 25s coins you need, count the number of 1s, 2s, 4s, 8s, etc
Why these numbers? They are powers of 2. This is a number in base 2
A single binary digit is a bit, e.g., 101 has three bits
An 8-bit group is called a byte, e.g., 10101010
Binary numbers grow as follows:
Practice Exercise 01:
What binary number represents 5?
What binary number represents 7?
What binary number represents 9?
What binary number represents 11?
To convert a binary number to decimal, just add each power of 2 that is represented by a 1.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 |
1001 1110 0000 1010
converts to Hex 9E0A
.Practice Exercise 02:
Convert the decimal number 13 to binary.
Convert the decimal number 13 to hexadecimal.
HTML uses hexadecimal to represent colours
Six-digit hex numbers specify colours:
Each pair of digits represents a colour component (RGB).
Each color channel typically has a range from 0 to 255 (in 8-bit systems), which gives a total of 256 intensity levels for each primary color.
When you combine the three channels, you get a possible color palette of \(256^3\) or about 16.7 million colours
H, e, l, l, o, space, W, o, r, l, d
For basic characters, we can use the encoding system called ASCII. This maps the numbers 0 to 255 to characters. Therefore, one character is represented by one byte
Check it out here: ASCII Table
“Hello World” =
01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100
01011001 01100001 01111001
To address this, Unicode was developed
Unicode is a superset of ASCII that includes characters from all languages, as well as symbols and emojis
The Unicode system represents every character that can be typed into a computer. It uses up to 5 bytes, which can represent up to 1 trillion characters!
UTF-8 stands for Transformation Format 8-bit
Find all the Unicode characters here: https://symbl.cc/en/unicode-table/
\u0044\u0061\u006e\u0069\u006c\u006f
\u0051\u0054\u004d\u0020\u0033\u0035\u0030
Decoder: https://symbl.cc/en/tools/decoder/
The Apollo 11 mission to the moon was programmed in assembly language
The code is available here: https://github.com/chrislgarry/Apollo-11 (good luck reading it! 😅)
One of the files is the BURN_BABY_BURN--MASTER_IGNITION_ROUTINE.agc
🔥 🚀
But if Assembly is so fast and efficient, why don’t we use it all the time?
C++
, Fortran
, Go
).R
, Python
).R> section .data
+ message db 'Hello, World!', 10 ; 10 is the ASCII code for newline
+
+ section .text
+ global _start
+
+ _start:
+ mov eax, 4 ; system call number for write
+ mov ebx, 1 ; file descriptor 1 is stdout
+ mov ecx, message ; address of string to output
+ mov edx, 14 ; number of bytes
+ int 0x80 ; call kernel
+
+ mov eax, 1 ; system call number for exit
+ xor ebx, ebx ; exit status 0
+ int 0x80 ; call kernel
Python
; distinction between compiled and interpreted languages1101
in binary.D
in hexadecimal.1101
.1101
(binary) = D
(hex).1101
to hexadecimal:1101
13
corresponds to the hexadecimal number D
.1101
is D
in hexadecimal.Step 1: Identify the binary strings: 01011001 01100001 01111001
Step 2: Convert each binary string to its decimal equivalent
Step 3: Map each decimal value to its corresponding ASCII character
Step 4: Combine the ASCII characters to form the final text