%%{init: {"flowchart": {"htmlLabels": false}} }%% graph LR A[Input] --> B[Processing] --> C[Storage] --> D[Output]
AESB2122 - Signals and Systems with Python
%%{init: {"flowchart": {"htmlLabels": false}} }%% graph LR A[Input] --> B[Processing] --> C[Storage] --> D[Output]
Binary 0 and 1 - Two states
%%{init: {"flowchart": {"htmlLabels": false}} }%% flowchart LR S0[Switch OFF: 0]:::off --> L0[Light OFF]:::off classDef off fill:#ff4d4d,color:#ffffff,stroke:#b30000,stroke-width:2px; classDef on fill:#4dff88,color:#000000,stroke:#00802b,stroke-width:2px;
%%{init: {"flowchart": {"htmlLabels": false}} }%% flowchart LR S1[Switch ON: 1]:::on --> L1[Light ON]:::on classDef off fill:#ff4d4d,color:#ffffff,stroke:#b30000,stroke-width:2px; classDef on fill:#4dff88,color:#000000,stroke:#00802b,stroke-width:2px;
%%{init: {"flowchart": {"htmlLabels": false}} }%% flowchart LR %% Define styles classDef off fill:#ff4d4d,color:#ffffff,stroke:#b30000,stroke-width:2px; classDef on fill:#4dff88,color:#000000,stroke:#00802b,stroke-width:2px; classDef S1 fill:#A7D13D,color:#000000,stroke:#b30000,stroke-width:2px; classDef S2 fill:#3DD1B6,color:#000000,stroke:#00802b,stroke-width:2px; %% State 00 S1_0[S1: 0]:::off --> ST00[00]:::S1 S2_0[S2: 0]:::off --> ST00 %% State 01 %% subgraph STATE01[State 01] S1_0b[S1: 0]:::off --> ST01[01]:::S2 S2_1[S2: 1]:::on --> ST01 %% end
%%{init: {"flowchart": {"htmlLabels": false}} }%% flowchart LR %% Define styles classDef off fill:#ff4d4d,color:#ffffff,stroke:#b30000,stroke-width:2px; classDef on fill:#4dff88,color:#000000,stroke:#00802b,stroke-width:2px; classDef S3 fill:#5884CC,color:#000000,stroke:#b30000,stroke-width:2px; classDef S4 fill:#A958CC,color:#000000,stroke:#00802b,stroke-width:2px; %% State 10 %% subgraph STATE10[State 10] S1_1[S1: 1]:::on --> ST10[10]:::S3 S2_0b[S2: 0]:::off --> ST10 %% end %% State 11 %% subgraph STATE11[State 11] S1_1b[S1: 1]:::on --> ST11[11]:::S4 S2_1b[S2: 1]:::on --> ST11 %% end
Data in a computer is represented using binary code (0s and 1s). Each switch (bit) can be in one of two states, allowing us to represent different values.
8 bits = 1 byte (typical unit of digital data storage)
Let’s see how 8 switches can show a 7
.
%%{init: {"flowchart": {"htmlLabels": false}} }%% flowchart TD A[7] -->|Binary| B[00000111]
Numbers: binary counting system
Text: ASCII/Unicode (e.g. A = 65 → 01000001)
Images: pixels stored as numbers (colors = binary values)
AND: bulb lights only if both switches ON
OR: bulb lights if either switch ON
NOT: bulb lights if switch OFF
Each switch is a transistor (tiny electronic switch)
Combine billions of transistors → circuits
Feature | CPU | GPU |
---|---|---|
Cores | Few (typically 4-16) | Many (hundreds to thousands) |
Task Handling | Sequential processing | Parallel processing |
Versatility | More versatile, can handle a wide range of tasks | Specialized, excels at very specific tasks |
Ideal Use Cases | General computing, single-threaded | Graphics rendering, machine learning |
Where data is kept for short-term or long-term use
Feature | Short-Term Storage | Long-Term Storage |
---|---|---|
Speed | Fast (e.g., RAM) | Slower (e.g., Hard Drive, SSD) |
Volatility | Volatile (data lost when powered off) | Non-volatile (data retained) |
Capacity | Limited (typically GBs) | Larger (TBs or more) |
Use Cases | Temporary data, active processes | Permanent data, file storage |
Feature | Local Storage | Cloud (Remote) Storage |
---|---|---|
Accessibility | Limited to physical location | Accessible from anywhere with internet |
Collaboration | Difficult (manual sharing) | Easy (real-time collaboration) |
Typically, anything you would like to store long-term will be in a file.
File: A collection of data (stored as sequence of bytes)
Could be a document, image, video, or program
A file has a name and an extension.
File extensions help identify the file type and associated programs.
File extensions are suffixes following a file name (.txt
, .jpg
, .py
, .ipynb
, .pdf
, etc.)
Metadata: size, type, modified date, etc.
Softwares can only open and edit particular file types that they are designed for. e.g. Microsoft Excel won’t be able to open your .ipynb
files.
Try opening an image file (.png
,.jpg
, etc.) with any text editor (e.g. Notepad, TextEdit, etc.)
Container to store files and subfolders
Hierarchical structure
Why do I need folders? Why can’t I have everything in my Downloads
folder?
Downloads
folder would become cluttered and chaotic.Do folders need extensions?
Please follow the mini module: https://teachbooks.io/files-and-folders
Way to communicate instructions to a computer
Computers only understand binary (0s and 1s)
Languages translate human ideas into machine-readable commands.
Examples: Python, Java, C, HTML.
Pure 0s and 1s, directly executed by CPU.
Extremely fast, but almost impossible for humans to read/write.
Example: To write 39
you would write 100111
.
Low-level symbolic language, one step above machine code.
Uses short mnemonics instead of raw binary (e.g., MOV, ADD).
Needs an assembler to convert to machine code.
Python, Java, C, JavaScript.
Easier to read/write, closer to human language.
Need compiler or interpreter to run.
LL are closer to machine code, while HL are closer to human language.
HL are generally easier to learn and use, making them more accessible for beginners, but …
… HL will not offer the same level of performance and efficiency as LL
LL are great for system programming, embedded systems, and performance-critical applications.
Note: Not a binary separation, but rather a spectrum of abstraction levels. For example, Python (highest), C (middle), and Assembly Language (lowest).
Tools in a toolbox: hammer ≠ screwdriver; each solves a different problem.
Different languages for different goals:
Performance-critical tasks → C, C++
Web development → JavaScript, HTML/CSS
Data analysis/science → Python, R
Mobile apps → Java/Kotlin (Android), Swift (iOS)
Trade-offs:
Ease of use vs execution speed
Flexibility vs strict rules
Hello world!
in Assemblysection .data
hello: db 'Hello world!',10 ; 'Hello world!' plus a linefeed character
helloLen: equ $-hello ; Length of the 'Hello world!' string
section .text
global _start
_start:
mov eax,4 ; The system call for write (sys_write)
mov ebx,1 ; File descriptor 1 - standard output
mov ecx,hello ; Put the offset of hello in ecx
mov edx,helloLen ; helloLen is a constant, so we don't need to say
; mov edx,[helloLen] to get it's actual value
int 80h ; Call the kernel
mov eax,1 ; The system call for exit (sys_exit)
mov ebx,0 ; Exit with return code of 0 (no error)
int 80h;
Hello world!
in C and PythonFrom writing code to running code…
If you’re in Windows File Explorer or Mac Finder, simply double clicking on a file will open it in the default application.
Like we discussed before, a file extension tells your computer which application to use to open it.
But what if we have files that contain code (i.e. scripts)? e.g. .py
files.
Double-clicking scripts will open them for editing, not for executing them (or running them).
Enter the terminal…
Feature | GUI | CLI |
---|---|---|
Interaction | Click/Drag/Point | Type commands |
Ease for beginner | Usually easier | Requires learning commands |
Flexibility | Limited | Very flexible |
Automation | Harder | Easy with scripts |
Using your computer’s file explorer (GUI), in Documents
, create a folder with your name and the course code as a suffix.
Inside it, create 2 text files with .txt
extension. Rename one with a .py
extension. (For Windows users, you can create directly through File Explorer. For Mac users, do it via a text editor (e.g. TextEdit or VSCode), renaming can be done through Finder.)
Copy the hello.py
file that you created during the “Python in a Terminal” lecture and paste it in this folder.
.txt
extension to .jpg
→ try to open. What happens?Use cd
to go into your folder.
List contents with ls
(or dir
on some Windows machines).
Use python hello.py
to run your script from the terminal.
Go one level higher in the directory structure using cd ..
Now run the command python hello.py
to run your script from the terminal. What happens?
How can you fix this and get the script running again?