233 Notes Section1
233 Notes Section1
ENGSCI 233
1
Objectives of 1.2 Binary representation
2
fl
Positive integer decimal representation
• Base 10.
• Digits, dn, can be any of 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9.
• Write as (dN dN−1 . . . d2 d1 d0)10, or simply dN dN−1 . . . d2 d1 d0, to
represent
(dN × 10N ) + (dN−1 × 10N−1) + . . . + (d2 × 102) + (d1 × 101) + (d0 × 100)
• For example
4210 = (4 × 101) + (2 × 100)
= (4 × 10) + (2 × 1)
and
172910 = (1 × 103) + (7 × 102) + (2 × 101) + (9 × 100)
= (1 × 1000) + (7 × 100) + (2 × 10) + (9 × 1)
• Most common representation of integers for use by humans.
3
Positive integer binary representation
• Base 2.
• Digits, dn, can be either 0, or 1.
• Binary digits, dn, are called bits.
• Write as dN dN−1 . . . d2 d1 d0 2 (or 0b dN dN−1 . . . d2 d1 d0 in C and
Python) to represent
(dN × 2N ) + (dN−1 × 2N−1) + . . . + (d2 × 22) + (d1 × 21) + (d0 × 20)
• For example, convert integer from binary to decimal:
0b101010 = 1010102
= (1 × 25) + (0 × 24) + (1 × 23) + (0 × 22) + (1 × 21) + (0 × 20)
= (1 × 32) + (0 × 16) + (1 × 8) + (0 × 4) + (1 × 2) + (0 × 1)
= 4210
• Most common representation of positive integers for use by by computers.
4
Convert positive integer from decimal to binary
5
Positive integer hexadecimal representation
• Base 16.
• Digits, dn, can be any of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, or f.
• Write as dN dN−1 . . . d2 d1 d0 16 (or 0x dN dN−1 . . . d2 d1 d0 in C and
Python) to represent
(dN × 16N ) + (dN−1 × 16N−1) + . . . + (d2 × 162) + (d1 × 161) + (d0 × 160)
• a16 = 1010, b16 = 1110, c16 = 1210, d16 = 1310, e16 = 1410, f16 = 1510,
• For example
0x2a = 2a16
= (2 × 161) + (a × 20)
= (2 × 16) + (10 × 1)
= 4210
• Hexadecimal is a more compact representation than decimal and binary.
6
Convert positive integer from hexadecimal to binary
7
Convert positive integer from binary to hexadecimal
8
fi
Convert positive integer from hexadecimal to decimal
• For example
0x6c1 = 6c116
= (6 × 162) + (c × 161) + (1 × 160)
= (6 × 256) + (12 × 16) + (1 × 1)
= 172910
9
Convert positive integer from decimal to hexadecimal
10
Computer word length
8 bit (1 byte);
1983 Nintendo 8 bit
16 bit (2 byte);
1990 Super Nintendo 16 bit
32 bit (4 byte);
11
fi
Effect of word length on the range of positive integers
• 8 bit range:
from 000000002 = 010
to 111111112 = 25510
• 16 bit range:
from 00000000 000000002 = 010
to 11111111 111111112 = 65,53510
• 32 bit range:
from 00000000 00000000 00000000 000000002 = 010
to 11111111 11111111 11111111 111111112 = 4,294,967,29510
• 64 bit range:
00000000 00000000 00000000 00000000...
from
. . .00000000 00000000 00000000 000000002 = 010
to
11111111 11111111 11111111 11111111...
. . .11111111 11111111 11111111 11111112 = 18,446,744,073,709,551,61510
12
Signed integer binary representation: sign-magnitude
13
fi
Signed integer binary representation: offset binary
• In offset binary representation (also called excess-K Bit pattern Eight bit
or biased), a signed integer is represented by the bit (8 bit) excess-128
pattern corresponding to the unsigned number plus 00000000 –128
K, where K is the biasing value or offset. 00000001 –127
00000010 –126
• Thus 0 is represented by K, and −K is represented ⋮ ⋮
by an all-zero bit pattern. 01111101 –3
• There is only one representation of 0: 01111110 –2
10000000 → 0 (for 8 bits). 01111111 –1
10000000 0
10000001 1
10000010 2
⋮ ⋮
11111101 125
11111110 126
11111111 127
14
Signed integer binary representation: two’s complement
15
Counting sheep in 16 bit two’s complement
16
Representation of real numbers
17
fi
Representation of real numbers as rational numbers
18
fi
Representation of real numbers as xed-point numbers
19
fi
fi
fi
fi
fi
fl
fi
Representation of real numbers as oating-point numbers
31 23 0
63 52 0
20
fl
fl
fl
fl
IEEE 754 single precision
31 23 0
21
fi
fi
fi
IEEE 754 single precision
31 23 0
22
fi
fi
Next section
👍
23
Image references
24
Computational techniques and computer systems
Module 1: Computer systems
1.3 Structured data
ENGSCI 233
1
Objectives of 1.3 Structured data
2
Which way does a computer read?
• Two possible ways that a computer can number bytes in larger groups:
• Little-endian:
• Stores least signi cant byte at the smallest memory address.
• Used in most PCs.
• Big-endian:
• Stores most signi cant byte at the smallest memory address.
• Used in mainframes and network equipment.
https://commons.wikimedia.org/wiki/File:Little-Endian.svg
https://commons.wikimedia.org/wiki/File:Big-Endian.svg
3
fi
fi
Which way does a computer read?
https://geek-and-poke.com/geekandpoke/2011/9/7/simply-explained.html
4
Binary
5
Character representation
6
Character representation: US-ASCII
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
000 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
010 ! “ # $ % & ‘ ( ) * + , - . /
011 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
100 @ A B C D E F G H I J K L M N O
101 P Q R S T U V W X Y Z [ \ ] ^ _
110 ` a b c d e f g h I j k l m n o
111 p q r s t u v w x y z { | } ~ DEL
7
The world is much richer than just ASCII
8
Character representation: Unicode
9
fi
How are Unicode characters stored?
• UTF-8 uses one, two, three, or four 8-bit code unit per code point.
• UTF-16 uses one or two 16-bit code units per code point.
• UTF-32 uses one 32-bit code unit per code point.
Encoding Bits A
☕ 💩
Unicode code
U+0041 U+2615 U+1F4A9
point
10
Some entities use more than one Unicode character
• e.g. ZWJ (zero width joiner) is the Unicode character (U+200D) that joins
two or more characters together in sequence to create a new emoji.
🏳🌈 = 🏳 + ZWJ + 🌈
👪 = 👨 + ZWJ + 👨 + ZWJ + 👧
👩🏭 = 👧 + ZWJ + + ZWJ + 🏭
11
What does this mean for you?
12
fi
What other types of data need to be represented?
13
fi
fi
fi
fi
What about pointers?
14
Next section
15
Image references
• Slide 3: https://commons.wikimedia.org/wiki/File:Little-Endian.svg
• Slide 3: https://commons.wikimedia.org/wiki/File:Big-Endian.svg
• Slide 4: https://geek-and-poke.com/geekandpoke/2011/9/7/simply-explained.html
• Slide 8: https://thenextweb.com/news/the-psychology-of-emojis
• Slide 8: https://preview.free3d.com/img/2017/10/2269153662355900306/nt44jac9.jpg
• Slide 8: https://www.google.com/url?sa=i&url=https://www.pinterest.com/pin/the-rosetta-
stone--522136150556126123/&psig=AOvVaw17J_ud965tgK1U0SU-
daza&ust=1678854504369000&source=images&cd=vfe&ved=0CBAQjRxqFwoTCPChh8XK2v0CFQAAAAAd
AAAAABAE
• Slide 8: https://cdn.pixabay.com/photo/2020/03/20/15/37/maya-script-4951005_1280.png
• Slide 14: https://upload.wikimedia.org/wikipedia/commons/thumb/8/82/NES-Console-Set.jpg/1600px-NES-
Console-Set.jpg?20201231095234
• Slide 14: https://commons.wikimedia.org/wiki/File:SNES-Mod1-Console-Set.jpg
• Slide 14: https://commons.wikimedia.org/wiki/File:PSX-Console-wController.jpg
• Slide 14: https://commons.wikimedia.org/wiki/File:Nintendo-64-wController-L.jpg
• Slide 15: In ection, by Randall Munroe, from https://xkcd.com/1709/
16
fl
Computational techniques and computer systems
Module 1: Computer systems
1.4 Computer architecture
ENGSCI 233
1
Objectives of 1.4 Computer architecture
2
What is a computer?
3
What is a computer? Human computers?
Computing Division of the US Veterans Bureau, 1924; NASA Ames “computers” at wind tunnel test facility, 1943
4
Computers have four parts
Memory Input/output
5
Computers have four parts
6
Computer systems add software
• Operating system:
• Sets standards for access to storage, transport, and I/O;
• Manages multiple programs running together.
• Drivers:
• Provide interface between hardware and software.
7
How do programs run on computers?
• Interpreter:
• A computer program that directly executes instructions written in a programming or scripting
language.
• Compiler:
• A computer program that translates instructions written in a programming language into an
executable.
8
What does code do?
9
Assembly language is dif cult to understand
10
fi
What does the processing?
• Semiconductor chips.
• May use many computing units in parallel on one or many separate chips.
M2 Max system on a chip, 12 core CPU, 38 core GPU, 64 bit ARMv8 instruction set, 67 billion transistors.
11
Processor performance
12
Processor performance
13
fl
fi
50 years of microprocessor trend data
50 Years of Microprocessor Trend Data
Transistors
(thousands)
107
106
Single-thread
105 performance
(SpecINT×103)
104
Frequency
(MHz)
103
Typical power
(W)
102
Number of
cores
101
100
Original data up to the year 2010 collected and plotted by M. Horowitz, F. Labonte, O. Shacham, K. Olukotun, L. Hammond, and C. Batten
Year
New plot and data collected for 2010-2021 by K. Rupp <https://github.com/karlrupp/microprocessor-trend-data>
Original data up to the year 2010 collected and plotted by M. Horowitz, F. Labonte, O. Shacham, K. Olukotun, L. Hammond, and C. Batten
New plot and data collected for 2010-2021 by K. Rupp 14
Supercomputers
15
Supercomputers
16
fl
Supercomputers
Moore’s law
17
Future?
18
fi
fi
Next section
19
Image references
20
fi
fi
fi
Image references
• Slide 8: https://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png
• Slide 8: https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Ruby_logo.svg/1280px-Ruby_logo.svg.png
• Slide 8: https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/Julia_Programming_Language_Logo.svg/
1920px-Julia_Programming_Language_Logo.svg.png
• Slide 8: https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/The_C_Programming_Language_logo.svg/
1280px-The_C_Programming_Language_logo.svg.png
• Slide 8: https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/Fortran_logo.svg/1280px-Fortran_logo.svg.png
• Slide 8: https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Ada_horizon_green_logo_with_slogan.svg/
2560px-Ada_horizon_green_logo_with_slogan.svg.png
• Slide 8: https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/Rust_programming_language_black_logo.svg/
1280px-Rust_programming_language_black_logo.svg.png
• Slide 11: https://www.apple.com/newsroom/images/product/mac/standard/Apple-M2-chips-M2-
Max-230117_big.jpg.large_2x.jpg
• Slide 14: Original data up to the year 2010 collected and plotted by M. Horowitz, F. Labonte, O. Shacham, K.
Olukotun, L. Hammond, and C. Batten. New plot and data collected for 2010-2021 by K. Rupp <https://github.com/
karlrupp/microprocessor-trend-data>
• Slide 16: https://www.geekwire.com/2019/cray-develop-insanely-fast-600m-el-capitan-supercomputer-u-s-nuclear-
simulations/
• Slide 17: https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/Supercomputing-rmax-graph2.svg/660px-
Supercomputing-rmax-graph2.svg.png
21
Computational techniques and computer systems
Module 1: Computer systems
1.6 Low level networking
ENGSCI 233
1
Objectives of 1.6 Low level networking
• Understand the physical means used to transfer data from one computer to
another.
• Discuss different ways that information can be encoded.
• Understand the use of error-correcting codes.
• Describe the key characteristics of ethernet.
2
How does computer networking operate?
3
fi
Computer networking is layered (like an onion)
Responsible for creating packets that move across Transfers packets with virtual (IP)
Network
the network addresses
Responsible for creating frames that move across Transfers frames with physical
Data link
the network (MAC) addresses
Physical Tranceiver that drives the signals on the network Transmits and receives bits
4
Physical layer
5
fi
Physical layer: electrical wire
• Limited length.
• Signals get weaker.
• Electrical interference.
6
Physical layer: optical bre
• Long lengths.
• Tens of kilometres.
• Across oceans with ampli ers…
7
fi
fi
fi
Physical layer: radio
• Broadcast to everyone!
• Serious interference possible.
• Increasing frequency:
• Higher bandwidth;
• Shorter range;
• Greater attenuation by walls, etc.
8
Multiplexing: Sharing a medium
9
fi
fi
Modulation: representing data in the medium
1 0 1 0 modulating
analogue medium. signal
10
fi
fi
fi
Data link layer
• The data link layer handles how data is transferred between devices on the
network, and may provide mechanisms to detect and possibly correct errors
that occur in the physical layer.
• Data are encapsulated in frames, enabling transmission between two nodes
connected by the physical layer.
11
Data link layer frame
• Errors are detected (but not corrected) using a 32-bit (4 byte) cyclic
redundancy check (CRC) or checksum.
0 4 8 12 16 20 24 28 31 bit
Destination MAC address
Destination MAC address Source MAC address
14 byte
Source MAC address
Ethernet type
46 byte to
Data
1500 byte
Checksum 4 byte
12
fi
Data link layer address
13
Error detecting codes
• Interference and noise can cause incorrect transmission and/or data loss.
• Error detecting codes use redundancy to detect transmission errors.
• A cyclic redundancy check (CRC) is widely used to detect errors in digital
data.
• CRC adds a xed-length check value to data before transmission.
• The check value is based on a simple algorithm applied to the data being sent.
• After transmission the check value is recalculated and compared with the CRC attached
before transmission.
• If the check values don’t match, corrective action must be taken (e.g. retransmission).
• Simplest CRC is parity bit (number of 1s in the data) which can only detect
a 1 bit error.
• 2-bit and higher CRCs can detect more than single bit errors.
14
fi
Error correcting codes
011 1
15
fi
Next section
16
Image references
17
fi
fl
fl
fi
fi
Computational techniques and computer systems
Module 1: Computer systems
1.7 High level networking
ENGSCI 233
1
Objectives of 1.7 High level networking
2
Computer networking is layered (like an onion)
Responsible for creating packets that move across Transfers packets with virtual (IP)
Network
the network addresses
Responsible for creating frames that move across Transfers frames with physical
Data link
the network (MAC) addresses
Physical Tranceiver that drives the signals on the network Transmits and receives bits
3
Network layer
• The network layer implements the internet protocol (IP) for delivering
packets across the network from the source to destination based solely on
IP addresses in the packet headers.
• The IP acts as a bridge between networks:
• Assigns globally unique IP addresses;
• Allows packets to be split up and reassembled;
• Discards old or stuck packets.
• IPv4 and IPv6 are the two most widely used versions of IP.
4
IPv4
5
fi
IPv4
6
IPv6
7
Routing
• When a packet arrives on one data line, the router uses information in its
routing table to send the packet to the next network
• Packets are forwarded from their source, through routers on the network,
until they reach their destination.
• High-level protocols discover the best route using methods such as
Dijkstra’s algorithm.
fi
Transport layer
9
fi
fi
Transport layer user datagram protocol (UDP)
8 byte to
Data
65507 byte
10
fi
fl
Transport layer transmission control protocol (TCP)
11
Transport layer transmission control protocol (TCP)
12
fi
fi
Application layer
13
fi
fi
fi
Tying the layers together
14
fi
fi
fi
fi
Tying the layers together
Network topology
Data link Data link Data link Data link Frame header Frame data Frame footer
15
fl
fi
Next section
16
Image references
• Slide 2: Map of the Internet, by Randall Munroe, from https://xkcd.com/195/ (CC BY-NC 2.5)
• Slide 3: Adapted from Neil Drumm, https://www. ickr.com/photos/drumm/2989736147 (CC BY-SA 2.0)
• Slide 15: Adapted from https://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/IP_stack_connections.svg/
1024px-IP_stack_connections.svg.png
• Slide 15: Adapted from https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/UDP_encapsulation.svg/
700px-UDP_encapsulation.svg.png
17
fl
Computational techniques and computer systems
Module 1: Computer systems
1.8 Software systems
ENGSCI 233
1
Objectives of 1.8 Software systems
2
Computer software is layered
Layer Purpose
Operating system Software that manages the operation of other software in a computer system
Hardware
3
fi
System design is exible
4
fl
fi
How does software use hardware?
Drive
RAM ROM hard disk or solid state
random access memory read only memory
CD / DVD
Static RAM PROM
faster, low power programmable ROM
USB flash drive
Dynamic RAM EPROM
slower, needs refreshing erasable PROM
Tape
EEPROM
electrically EPROM
5
Static memory allocation
6
fi
Stack-based memory allocation
7
fi
fl
Heap-based memory allocation
8
Device drivers
9
fi
Python imports device drivers
10
fi
Python can import many things
• Helpful libraries:
• import numpy as np
• import matplotlib.pyplot as plt
• Other software:
• from git import Repo
• from selenium.webdriver import
Firefox
• Device drivers:
• import serial
• import mouse
• Outside services:
• from bitbucket.client import Client
• from pydrive.drive import GoogleDrive
11
There are many useful APIs available
12
fi
APIs can make programming look easy
13
Next section
14
Image references
• Slide 2: Old Days, by Randall Munroe, from https://xkcd.com/1755/ (CC BY-NC 2.5)
• Slide 4: (right) from https://commons.wikimedia.org/wiki/File:Cloud_computing_icon.svg (CC BY-SA 3.0)
• Slide 6: Steven Depolo, from https://www. ickr.com/photos/stevendepolo/3072821281 (CC BY-NC 2.0)
• Slide 9: from https://commons.wikimedia.org/wiki/File:SanDisk-Cruzer-USB-4GB-ThumbDrive.jpg (Public
domain)
• Slide 9: by Dmitry Nosachev, from https://commons.wikimedia.org/wiki/File:Supermicro_AOC-SGP-
I2_Gigabit_Ethernet_NIC,_PCI-Express_x4_card.jpg (CC BY-SA 4.0)
• Slide 11: Python, by Randall Munroe, from https://xkcd.com/353/ (CC BY-NC 2.5)
• Slide 12: from https://www.reddit.com/r/ProgrammerHumor/comments/69uof3/programming_stack_over ow/
15
fl
fl
Computational techniques and computer systems
Module 1: Computer systems
1.9 Operating systems
ENGSCI 233
1
Objectives of 1.9 Operating systems
2
Computer software is layered
Layer Purpose
Operating system Software that manages the operation of other software in a computer system
Hardware
3
fi
Operating system
Operating system
Device drivers
Firmware
Hardware
4
Manages hardware and software resources
• Cooperative multi-tasking:
• Programs are written to take turns;
• What happens if one forgets?
• Preemptive multi-tasking:
• The OS gives out time slices and manages switching tasks between slices;
• Hardware can generate interrupts to wake up software when needed.
• Multi-threading
• Separate processes in one program that share memory;
• Uses the same multi-tasking approach as separate programs.
5
Manages hardware and software resources
6
Manages hardware and software resources
7
Provides standard interfaces
https://learn.microsoft.com/en-us/windows-hardware/drivers/audio/windows-audio-architecture
8
Provides common services for programs
• Common services for programs include APIs for using and managing:
• File system;
• Memory allocation;
• Virtual memory;
• Network protocols;
• Security authentication;
• And many more…
9
Operating system examples (desktop)
10
Operating system examples (mobile)
11
Operating system examples (embedded/real time)
12
fi
Operating system examples (server/distributed)
13
fi
Next section
14
Image references
• Slide 2: Operating Systems, by Randall Munroe, from https://xkcd.com/1508/ (CC BY-NC 2.5)
• Slide 8: from https://learn.microsoft.com/en-us/windows-hardware/drivers/audio/windows-audio-architecture
• Slide 10: from https://commons.wikimedia.org/wiki/File:MacOS_logo.svg
• Slide 10: from https://commons.wikimedia.org/wiki/File:Windows_11_logo.svg
• Slide 10: from https://en.wikipedia.org/wiki/Linux#/media/File:Tux.svg
• Slide 11: from https://commons.wikimedia.org/wiki/File:IOS_wordmark_(2017).svg
• Slide 11: from https://commons.wikimedia.org/wiki/File:Android_logo_2019_(stacked).svg
• Slide 12: from https://en.wikipedia.org/wiki/VxWorks#/media/File:VxWorks_icon.svg
• Slide 12: from https://github.com/ARMmbed/mbed-os/blob/master/logo.png
• Slide 12: from https://www.lynx.com/hs-fs/hubfs/LynxOS® Logo white blue drop shadow.png?
width=3152&name=LynxOS® Logo white blue drop shadow.png
• Slide 12: from https://github.com/qnx
• Slide 13: from https://en.wikipedia.org/wiki/Linux#/media/File:Tux.svg
• Slide 13: from https://www.freebsd.org/
• Slide 13: from https://en.wikipedia.org/wiki/Windows_Server#/media/File:Windows_Server_logo.svg
• Slide 13: from https://logowik.com/ibm-zos-logo-vector-svg-pdf-ai-eps-cdr-free-download-19500.html
15