cpsc 171 introduction to computer science
DESCRIPTION
CPSC 171 Introduction to Computer Science. Binary. Announcements. Read Chapter 4 Lab 4 & 5 due tomorrow at beginning of Lab Homework 3 due this Friday at beginning of Lecture EXAM Friday October 2 nd in class. Real World - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/1.jpg)
CPSC 171 Introduction to Computer Science
Binary
![Page 2: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/2.jpg)
Announcements
Read Chapter 4Lab 4 & 5 due tomorrow at beginning of LabHomework 3 due this Friday at beginning of LectureEXAM Friday October 2nd in class
![Page 3: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/3.jpg)
Example Representation
Real WorldTo be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd.-- William Shakespeare - (from Hamlet Act 3, Scene 1)
Computer World101010001101111100000011000101010100011011001100110011000101110111011111100010101011010100010110111011000101010110001011011101001000100010101010111010101011011010010111101010001101111100000011000101010100011011001100110011000101110111011111100010101011010100010110111011000101010110001011011101001000100010101010111010101011011010010111101010001101111100000011000101010100011011001100110011000101110111011111100010101011010100010110111011000101010110001011011101001000100010101010111010101011011010010111…
![Page 4: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/4.jpg)
Internal and External Representation of Data
Real WorldIntegers: 34Signed Integers: -156Decimal Numbers:-23.431Text: HelloMusic: Hey JudePictures:
Computer WorldZeros and Ones:110101
![Page 5: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/5.jpg)
Integer RepresentationWe use a base 10 number system (Decimal)0, 1, 2, 3, 4, 5, 6, 7, 8, 9
2,359
tens
hund
reds
thou
sand
son
es
100
101
102
103
Computers use a base 2 number system (Binary)0, 1
110101
20
21
22
23
24
25
![Page 6: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/6.jpg)
Conversion from Binary to Decimal
1x25+1x24+0x23+1x22+0x21+1x20=53
You Try it:What are the following binary numbers in
decimal?11011101100110111
110101 20
21
22
23
24
25
![Page 7: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/7.jpg)
Conversion from Decimal to Binary
Perform repeated divisions by 2Keep track of the remainders
19 / 2 quotient = 9 remainder = 19 / 2 quotient = 4 remainder = 14 / 2 quotient = 2 remainder = 02 / 2 quotient = 1 remainder = 01 / 2 quotient = 0 remainder = 1
Stop when the quotient is 0Decimal number 19 in binary is 10011
You Try itConvert the following decimal numbers to binary123153
![Page 8: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/8.jpg)
Addition on Binary
0 + 0 = 01 + 0 = 10 + 1 = 11 + 1 = 10 (carry the 1)
1101 11010
+1001 +10011
![Page 9: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/9.jpg)
Fixed Sizes for Numbers
On computers a fixed number of digits are typically used to store a number(8, 16, 32, or 64 bits are common)The decimal number 3 in binary is 11, but using a fixed size of 8 bits it would be represented as 00000011Try adding the binary numbers using a fixed size of 8 bits: 11011001+10001011
![Page 10: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/10.jpg)
Internal and External Representation of Data
Real WorldIntegers: 34Signed Integers: -156Decimal Numbers:-23.431Text: HelloMusic: Hey JudePictures:
√
![Page 11: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/11.jpg)
Signed Integers
-134
Sign/Magnitude Notation 110000110
magnitude
Sign0 = positive1 = negative
Not frequently used on computers•2 numbers for zero•Not easy to add/subtract
![Page 12: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/12.jpg)
Signed Integers
-134
Two’s Complement Notation (for fixed size window 16)
1. Calculate the magnitude in binary0000000010000110
2. Flip the bits1111111101111001
3. Add one1111111101111010You Try it-129 -151
![Page 13: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/13.jpg)
Internal and External Representation of Data
Real WorldIntegers: 34Signed Integers: -156Decimal Numbers:-23.431Text: HelloMusic: Hey JudePictures:
√√
![Page 14: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/14.jpg)
Decimal Numbers5.75Write the 5 in binary and the 0.75 in binary5 – 1010.75 – 0.11Normalize the number, keeping track of Mantissa and
Exponent:±MxB±E
M – MantissaB – Base (we use base 2)E – Exponent
Used fixed size window (16 bits)First bit is signNext 9 bits are MantissaNext bit is signLast 5 bits are Exponent
You Try It: -8.25 11.5
![Page 15: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/15.jpg)
Text
Fixed Size Window represents a characterASCII (8 bits) pg 141 in textUnicode (16 bits) represents 65,636 characters
![Page 16: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/16.jpg)
Binary Representation of Sound and Images
Multimedia data is sampled to store a digital form with or without detectable differences
Representing sound data
Sound data must be digitized for storage in a computer
Digitizing means periodic sampling of amplitude values
![Page 17: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/17.jpg)
Binary Representation of Sound and Images (continued)
From samples, original sound can be approximated
To improve the approximation
Sample more frequently
Use more bits for each sample value
![Page 18: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/18.jpg)
Figure 4.5Digitization of an Analog Signal
(a) Sampling the Original Signal
(b) Recreating the Signal from the Sampled Values
![Page 19: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/19.jpg)
Representing image data
Images are sampled by reading color and intensity values at even intervals across the image
Each sampled point is a pixel
Image quality depends on number of bits at each pixel
Binary Representation of Sound and Images (continued)
![Page 20: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/20.jpg)
Pictures
For each pixel keep track of: RGB values 0-255 (8-bit)
![Page 21: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/21.jpg)
Why Binary Representation
Electronic devices are most reliable in a bistable environment
Bistable environment Distinguishing only two electronic states
Current flowing or not
Direction of flow
Computers are bistable: binary representations
![Page 22: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/22.jpg)
Magnetic core
Historic device for computer memory
Tiny magnetized rings; flow of current sets the direction of magnetic field
Binary values 0 and 1 are represented using the direction of the magnetic field
Binary Storage Devices
![Page 23: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/23.jpg)
Figure 4.9Using Magnetic Cores to Represent Binary Values
![Page 24: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/24.jpg)
Transistors
Solid-state switches; either permit or block current flow
A control input causes state change
Constructed from semiconductors
Binary Storage Devices (continued)
![Page 25: CPSC 171 Introduction to Computer Science](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813b6d550346895da472d1/html5/thumbnails/25.jpg)
Figure 4.11Simplified Model of a Transistor