I. Computers store all information as a sequence of bits.
A. Binary Number System
i. Humans write integers in decimal (base-10). Each digit has 10 possible values: 0 - 9
703610 = 7 x 103 + 0 x 102 + 3 x 101 + 6 x 100
ii. Computers represent integers in binary (base-2). Each digit has 2 possible values: 0 or 1
1001102 = 1 x 25 + 0 x 24 + 0 x 23 + 1 x 22 + 1 x 21 + 0 x 20
= 3210 + 410 + 210
= 3810
iii. Storing 3810 in binary (base-2) requires 6 bits (binary digits).
iv. Storing this value in one byte would be 00100110.
v. Storing the same value in two bytes would be 0000000000100110.
vi. Storing large integers in binary requires a lot of bits.
vii. The largest one-byte binary integer would be
111111112 = 25510
viii. The largest two-byte binary integer would be
11111111111111112 = 6553510
ix. The smallest two-byte binary intger would be
00000000000000002 = 010
B. Two's Complement Number System
i. In the binary number system, a negative number requires the use of a negative sign
-1001102 = -3810
ii. To distinguish positive and negative numbers, a computer uses the two's complement number system for negative numbers.
iii. In this system, if the left most bit is a 0, the integer value is positive and represented in binary (base-2).
iv. If the left most bit is a 1, the number is negative and the absolute value of the negative number is not in binary, but is the two's complement of the original
v. To find the two's complement
1. Change each 1 to 0, and each 0 to 1.
2. Add one to the number and discard any carry bit.
vi. Examples
a. Given 10101100, what integer value is represented?
It is a negative integer since the left most bit is a 1, therefore find its two's complement
1. 01010011 (flip bits)
2. + 1 (add one)
-----------
01010100 = 6410 + 1610 + 410 = 8410
The integer value represented by 10101100 is therefore -8410.
b. Given 00101100, what integer value is represented?
It is a positive integer since the left most bit is a 0, therefore simple determine it binary value
00101100 = 3210 + 810 + 410 = 4410
c. How do you represent -9410?
9410 = 6410 + 1610 + 810 + 410 + 210
= 26 + 24 + 23 + 22 + 21
= 010111102
Since we want to represent a -9410, we find two's complement of 9410.
1. 10100001 (flip bits)
2. + 1 (add one)
-----------
10100010
The integer value -9410 is represented as 10100010.
A. Floating-point numbers are numbers containing fractional information. Humans write floating-point numbers in decimal (base-10).
6.3410 = 6 34/10010 = 6 x 100 + 3 x 10-1 + 4 x 10-2
B. Computers represent floating-point numbers in binary (base-2).
101.0112 = 1 x 22 + 1 x 20 + 1 x 2-2 + 1 x 2-3
= 410 + 110 + 1/410 + 1/810
= 5 3/810
C. Floating-point numbers can be expressed in two forms, fixed notation or scientific notation. Computers express floating-point numbers in scientific notation which consists of a mantissa, base, and exponent. For example, in the floating-point number
6.02 x 1023
6.02 is the mantissa, 10 is the base, and 23 is the exponent.
D. Computers store the scientific notation of the number in three pieces: a sign bit, an exponent, and a mantissa. In 16-bits for example, a floating point number could be stored as a sign bit, 5 exponent bits, and 10 mantissa bits. The base is not stored because it is given to be 2.
s e e e e e m m m m m m m m m m
A sign bit of 0 is means positive, and 1 means negative. The exponent is simply an integer (positive or negative), and the mantissa is stored in the remainder where left most mantissa bit may not be 0.
E. To store a floating-point number, the fixed notation of form of the base-10 representation is converted to base-2. The base-2 fixed notation is then changed to scientific notation. The scientific notation is adjusted so the binary point (similar to the decimal point in base-10) is left of the most significant digit in the mantissa. The resulting base-2 exponent and mantissa are then stored by the computer.
F. How do you store 13.12510?
1. Convert fixed notation base-10 to base-2
13.62510 = 810 + 410 + 110 + 1/210 + 1/810
= 23 + 22 + 20 + 2-1 + 2-3
= 1101.1012
2. Change base-2 fixed notation to scientific notation
1101.1012 = 1101.101 x 20
3. Move binary point to the left
1101.101 x 20 = .1101101 x 24
4. Store sign bit, exponent, and mantissa
0 00100 1101101000
G. Many floating point numbers cannot be represented exactly since there are a finite number of bits used to store the mantissa. For example the following base-2 floating point number could not be store exactly in our 16-bit format:
10100110.10011110101010100100111110101
It would be truncated to
10100110.10
and stored as
.1010011010 x 28