Lecture 02 - Computational Literacy
Department of Quantitative Theory and Methods
Emory University
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?
Solutions:
5 = 101
7 = 111
To convert a binary number to decimal, just add each power of 2 that is represented by a 1.
\(2^7\) (128) | \(2^6\) (64) | \(2^5\) (32) | \(2^4\) (16) | \(2^3\) (8) | \(2^2\) (4) | \(2^1\) (2) | \(2^0\) (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 |
Let’s explore the RGB model interactively!
1001 1110 0000 1010
converts to Hex 9E0A
.
1001
\(_2\) = 9\(_{16}\)1110
\(_2\) = E\(_{16}\)0000
\(_2\) = 0\(_{16}\)1010
\(_2\) = A\(_{16}\)Practice Exercise 02:
Convert the decimal number 13 to binary.
Convert that binary number to hexadecimal.
HTML and CSS use hexadecimal to represent colours.
Six-digit hex numbers specify colours: #RRGGBB
#FFFFFF
= White (Red=FF, Green=FF, Blue=FF)#000000
= Black (Red=00, Green=00, Blue=00)#FF0000
= Red (Red=FF, Green=00, Blue=00)Each pair of hex digits represents a colour component (00 to FF, which is 0 to 255 in decimal).
Each color channel (8-bit) has 256 intensity levels.
Total possible colours: \(256 \times 256 \times 256 = 256^3 \approx 16.7\) million colours.
#FF0000
: Full Red (Red=FF, Green=00, Blue=00)#00FF00
: Full Green (Red=00, Green=FF, Blue=00)#0000FF
: Full Blue (Red=00, Green=00, Blue=00)#000000
: Black (Red=00, Green=00, Blue=00 – no light)#FFFFFF
: White (Red=FF, Green=FF, Blue=FF – all light at full intensity)#FFFF00
: Yellow (Red=FF, Green=FF, Blue=00)#00FFFF
: Cyan (Red=00, Green=FF, Blue=FF)#FF00FF
: Magenta (Red=FF, Green=00, Blue=FF)#RGB
):
#F00
is equivalent to #FF0000
(Red)#0A3
is equivalent to #00AA33
(a dark green)#FFF
is equivalent to #FFFFFF
(White)00
is fully transparent (invisible)FF
is fully opaque (solid)80
is 50% opaque)#RGBA
): Similar to the 3-digit shorthand, but for colours with an alpha channel.#F008
would be equivalent to #FF000088
(semi-transparent red, with alpha 88 hex).In this lecture, we covered:
Decimal 13 to binary:
1101
in binary (1101\(_2\)).Binary 1101
to hexadecimal:
1101
.1101
to its hexadecimal equivalent:
1101
\(_2\) = \((1 \times 8) + (1 \times 4) + (0 \times 2) + (1 \times 1) = 8 + 4 + 0 + 1 = 13\) in decimal.D
in hexadecimal.1101
is D
in hexadecimal (D\(_{16}\)).