CS Unit 1
CS Unit 1
0 0 1 1
AND 0 AND 1 AND 0 AND 1
--------- --------- --------- ---------
0 0 0 1
_________________________________________________________
0 0 1 1
OR 0 OR 1 OR 0 OR 1
--------- --------- --------- ---------
0 1 1 1
_________________________________________________________
0 0 1 1
XOR 0 XOR 1 XOR 0 XOR 1
--------- --------- --------- ---------
0 1 1 0
_________________________________________________________
Hexadeciaml Notation
● A shorthand notation for long bit patterns
○ Divides a pattern into groups of four bits each
○ Represents each group by a single symbol
● Example: 1011 0101 ceomes 0xB5
Main Memory
● Cell: a unit of main memory (typically 8 bits which is one byte)
○ Most significant bit: the bit at the left (high order) end
○ Least significant bit: the bit at the right (low order) end
● Address: a “name” that uniquely identifies one cell in the computer’s main memory
○ The names are actually numbers
○ These numbers are assigned consecutively starting at zero
○ Numbering the cells in this manner associates an order with the memory cells
● Random Access Memory (RAM): Memory in which individual cells can be easily accessed in
any order
● Dynamic Memory (DRAM): RAM composed of volatile memory
Additional Mass Storages
● Magnetic Disks
● CDs
● DVDs
● Magnetic Tapes
● Flash Drives
● Solid-state Drives
Advantages over main memory
● Less volatility
● Larger storage capacities
● Low cost
● In many cases can be be removed
Mass Storage Performance
● Bandwidth: The total amount of bits that can be transferred in a unit of time
● Latency: The total time between the request for data transfer and its arrival
Hard Disks
● The hard disk arms nive the read/write head, which reads items and writes items in the drive
○ Location often is referred ti by its cylinder
● A head crash occurs when a read/write head touches the surface of a platter
● Always keep a backup of your hard disk
Flash Drives
● Flash Memory - circuits thats traps electrons in tiny silicon dioxide chambers
● Repeated erasing slowly damages the media
● Mass storage of choice for:
○ Digital cameras
○ Smartphones
● SD Cards provide GBs of storage
Representing Information as Bit Patterns
Many different kidns of information can be encoded as bit patterns
Systems for encoding information have been established for
● Text
● Numeric Data
● Sound
● Images
● Other Data
Representing Text
● Each character (letter, punctuation, etc.) is assigned a unique bit pattern
○ ASCII: uses patterns of 7-bits to represent most symbols used in written English text
○ ISO developed a number of 8 bit extensions to ASCII, each designed to accommodate a
major language group
○ Unicode: uses patterns up to 21-bits to represent the symbols the symbols used in
languages world wide, 16-bits for world’s commonly usde languages
Representing Numeric Values
● Binary Notation: uses bits to represent a number stored in sequences of 0s and 1s
● Counting from 0 to 8:
○ 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000
Representing Images
● Bit map techniques
○ Pixel: “picture element” represents one dot
○ RGB: Red, green, blue components
○ Luminance and chrominance
○ Problems with scaling up images
● Vector techniques
○ Represent images with geometric structs
○ Scakabke
○ TrueType and PostScript
Representing Sound
● Sampling techniques that record actual audio
○ Long-distance telephone: 8000 samples/sec
○ CD sound: 44,100 samples/sec
● MIDI stores directions for making sound
○ Used in music synthesizers
○ Encodes which instrument, note, and duration
Storing Integers
● Two’s complement notation: The most popular means of representing integer values
● Excess notation: Another means of representing integer values
The Problem of Overflow
● There is a limit to the size of the values that cna be represented in any system
● Overflow
○ Occurs when a computation produces a value that falls outside the range of values that
can be represented in the machine
○ If the resulting sign bit is incorrect, an overflow has occurred
○ 16 bit systems have been upgrades to 32 bit systems
Storing Fractions
● Floating-point Notation: consists of a sign bit, a mantissa field, and an exponent field
○ Normalized form: fill the mantissa starting with the left-most 1
2 5/8
10.101
1010 1 ------> "Lost Bit"
0 110 1010
Python: a popular programming language for applications, scientific computation, and as an introductory
language for students
An interpreted language
- Typing
print('Hello, World!')
- Results
Hello, world!
Variables: name values for later use
Analogous to mathematic variables in algebra
s = 'Hello, world!'
print(s)
my_integer = s
my_floating_point = 26.2
my_Boolean = True
my_sting = 'characters'
my_integer = 0xff
Operators and Expressions
print(3 + 4) #Prints 7
print(5 - 6) #Prints -1
print(7 * 8) #Prints 56
print(45 / 4) #Prints 11.25
print(2 ** 10) #Prints 1024
s = 'hello' + 'world'
s=s*4
print(s)
Currency Converstion
# A converter for currency exchange
USD_to_GBP = 0.66 #Today's exchange rate
GBP_sign = '\u00A3' #Unicode value for E
dollars = 1000 #Number dollars to convert
#Conversion Calculations
pounds = dollars *USD_to_GBP
Debugging
Syntax errors
print(5 +)
SyntaxError: invalid syntax
pront(5)
NameError: name 'pront' is not defined
Semantic Errors
Incorrect expressions like
total_pay = 40 + extra_hours * pay_rate
Runtime Errors
Unintentional divide by zero
Data Compression
Lossy versus lossless
Run-length encoding
Frequency-depending encoding
(Huffman codes)
Relative encoding
Differential Encoding
Dictionary encodings (Includes adaptive dictionary encoding such as LZW encoding)
Communication Errors
Goal: to reduce errors and increase the reliability of computing equipment
Parity bits (even versus odd)
Checkbytes
Error correcting codes
Hamming Distance