Topic 02: Computational Literacy
May 15, 2024
Computational Literacy
Simplest ways to physically represent numbers for arithmetic:
The first four-species calculating machine, which means that it is able to perform all four basic operations of arithmetic.
Built by Gottfried Wilhelm Leibniz in 1694.
If you took a statistics course before late 1970’s, you may have found yourself using this sort of mechanical calculator.
The 1970s marked the transition from mechanical to electronic:
Transistors act as switches for electronic signals
Integrated circuits on silicon microchips
Von Neumann architecture revolution
Main feature: the program and any data are both stored together, usually in a slow-to-access storage medium such as a hard disk, and transferred as required to a faster, and more volatile storage medium (RAM) for execution or processing by a central processing unit (CPU).
Since this, it is how practically all present day computers work, the term “Von Neumann architecture” is rarely used now, but it was in common parlance in the computing profession through to the early 1970s.
When Von Neumann proposed this architecture in 1945, it was a radical idea. Prior to then, programs were viewed as essentially part of the machine, and hence different from the data the machine operated on.
In modern digital computers, transistors act as switches, with 1 for high voltage level and 0 for low voltage level.
Computers use binary because transistors are easy to fabricate in silicon and can be densely packed on a chip.
A binary number is written using only the digits 0 and 1.
A single binary digit is a bit, e.g., 101 has three bits.
An 8-bit group is called a byte.
Binary numbers grow as follows:
Question: What binary number represents 3?
Question: What binary number represents 3?
Answer: b. 11
What binary number represents 5?
What binary number represents 7?
What binary number represents 9?
What binary number represents 11?
Machine code or binary code is binary instructions that a CPU reads and executes, such as: 10001000 01010111 11000101 11110001 10100001 00010110.
Early programming was done directly in machine code!
Question: How many distinct numbers are represented by a byte?
Question: How many distinct numbers are represented by a byte?
Answer: B) \(2^8\)
Write the characters of your name using ASCII codes.
Here we have an online translator!
‘DAVI’ using ASCII codes.
Character | ASCII Code |
---|---|
D | 68 |
A | 65 |
V | 86 |
I | 73 |
Note: If ASCII does not support characters in your name, Unicode will provide a solution.
Each hex digit corresponds to 4 binary bits:
One hex digit represents 4 bits, making it a shorthand for binary.
This is due to the fact that four binary digits can represent sixteen possible values (\(2^4\)), which aligns with the sixteen possible values of a single hex digit (0 to F).
1001 1110 0000 1010
converts to Hex 9E0A
.Convert the decimal number 13 to binary.
Convert the decimal number 13 to hexadecimal.
Now, convert the decimal number 27 to binary and then to hexadecimal.
HTML uses hexadecimal to represent colors.
Six-digit hex numbers specify colors:
Each pair of digits represents a color 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 colors.
For example, an RGB value of 255, 0, 0 corresponds to bright red because the red channel is at full intensity, and the green and blue channels are off.
Encountering a UnicodeDecodeError
in Python indicates a character encoding issue.
This often arises when dealing with characters not represented in the ASCII set.
UnicodeEncodeError
for these cases.To write “DAVI” in Unicode (UTF-8) using hexadecimal code points, you would use the Unicode code points for each character.
In UTF-8, the characters in the standard ASCII set, which includes uppercase English letters, are represented by the same values as in ASCII. The code points for ‘D’, ‘A’, ‘V’, and ‘I’ are as follows:
“DAVI” in Unicode (UTF-8) using these escape sequences would be represented as “\u0044\u0041\u0056\u0049”.
High-Level Languages: Abstract from hardware details, portable across different systems.
Low-Level Languages: Closer to machine code, require consideration of hardware specifics.
Compiled Languages: Convert code to binary instructions before execution (e.g., C++
, Fortran
, Go
).
Interpreted Languages: Run inside a program that interprets and executes commands immediately (e.g., R
, Python
).
Python
with C++
libraries).Python
; distinction between compiled and interpreted languages.Data Science Computing