Calibrating L-A Model to Chinese Stocks Chun Chen Sharalyn Chen Fei Lin Hechen Yu.
COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.6 Instructor: Lin Chen Sept...
-
Upload
gregory-rogers -
Category
Documents
-
view
215 -
download
0
Transcript of COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.6 Instructor: Lin Chen Sept...
COMPUTER SCIENCEData Representation and Machine ConceptsSection 1.6
Instructor: Lin Chen
Sept 2013
1.6 Storing Integers
1 Data Storage
Two’s Complement
Excess Notation
Pearson Custom: Computer Science, Data Representation and Machine Concepts
http://ocw.mit.edu/courses/aeronautics-and-astronautics/16-01-unified-engineering-i-ii-iii-iv-fall-2005-spring-2006/comps-programming/number_systems.pdf
Two’s Complement
1.6 Storing Integers
Use a fixed number of bits to represent each of the values in the system
First bit is used to represent the sign, 1 represents negative number, 0 represent nonnegative number
A negative number is represented by inverting the bits of its corresponding positive number in each place, then add 1 to the inverted number
Suppose to use 4 bits to represent the number
01112 = 7 10
10002
10012 = -7 10
+1
Two’s Complement
1.6 Storing Integers
Write the two’s complement notation for -6, -3, -1.
Two’s Complement
1.6 Storing Integers
Bit Pattern
Value Represented
0111 70110 60101 50100 40011 30010 20001 10000 01111 -11110 -21101 -31100 -41011 -51010 -61001 -71000 -8
Four Bits
Two’s Complement
1.6 Storing Integers
Addition7 – 2 = 7 + (-2) = ?
01111110+
10101
Two’s Complement
1.6 Storing Integers
Addition7 – 2 = 7 + (-2) = ?
01111110+
10101
Use four bits
01012 = 510
Two’s Complement
1.6 Storing Integers
Use two’s complement notation to calculate:7 – 5 = ?-3 – 4 = ?6 – 4 = ?-2 – 5 = ?
Two’s Complement
1.6 Storing Integers
What is the range of numbers that can be represented using the 2’s complement?
Answer: 2N-1 – 1 to -2N-1
Three bits: 3 to -4
Four bits: 7 to -8
Eight bits: ?
N is the number of bits
Two’s Complement
1.6 Storing Integers
List all the number with the two’s complement notation using 3 bits
Express 16 - -16 with the two’s complement notation using 8 bits
Two’s Complement
1.6 Storing Integers
Overflow
Calculate 5 + 4 with two’s complement notation using 4 bits
Excess Notation
1.6 Storing Integers
Steps:
1. Add the excess value 2N-1 to the number, where N is the number of bits used
2. Convert the resulting number into binary format
Suppose use 4 bits
-6 + 8
24-1
= 2 0010
Two’s Complement
1.6 Storing Integers
Write -8 to 7 with excess notation with 4 bits
Write -4 to 3 with excess notation with 3 bits