Professional Documents
Culture Documents
Spring 2004
Computers store numbers, text, .... (any data) in
binary
computers are just electrical circuits
binary numbers (1, 0) are indications of voltage levels
Binary representation of numerical
through these circuits (1 = “high”, 0 = “low”)
data Text, audio, video: later
Numbers: need to represent
April 14, 2004 integers
reals (decimal values)
negative and positive numbers
Integers Integers in base n
Base-10 integers: have a series of digits whose Have same notion of position and digits
value depends on the relative position of these digits: {0, 1, ... n-1}
digits
positions: powers of n
e.g. 543 = 5 100's, 4 10's, 3 1's
Example:
1342 in base 6 = 1*63 + 3*62 + 4*61 + 2*60
e.g. 13245 = 1*104 + 3*103 + 2*102 + 4*101 + 5*100
as on the previous slide idea: find the largest power of n that fits into that
Examples: decimal number
1342 in base 6 = 1*63 + 3*62 + 4*61 + 2*60 = 350 in at each stage, the remainder becomes the leftmost
base 10 digit
10101 in base 2 (binary) = 1*24 + 0*23 + 1*22 + 0*21 carry the quotient to the next stage
00100101 in binary = 1*25 + 1*22 + 1 = 37 in base 10
543 to base 5:
543/5 = 108 rem 3 491/2 = 245 rem 1
122/2 = 61 rem 0
21/5 = 4 rem 1
61/2 = 30 rem 1
4/5 = 0 rem 4 30/2 = 15 rem 0
7/2 = 3 rem 1
982 to binary = ?
3/2 = 1 rem 1
1/2 = 0 rem 1
= 1111010110
Representing negative numbers in Another way to represent negative
binary numbers: two's complement
Allows us to represent negative numbers in
One approach: signed-magnitude
(0=positive, 1=negative), and the other 7 bits are the All positive numbers start with a 0, as before
value Negative numbers:
can represent all numbers from -127 to 127
Invert all the bits (change 0's to 1's and 1's to 0's)
examples:
1 = 00000001, -1 = 10000001
65 = 01000001, -65 = 11000001
More two's complement examples Scientific notation
-7: Expressing very large or very small numbers can
7 is 00000111 be tedious
add 1: 10000001
0.245689734921 = 2.457 x 10-1 a and N are both binary
Multiply fractional part by 2 0.25*2 = 0.5
0.5 * 2 = 1.0
Integer part of the answer becomes the next
= 0.001
= -1010.001 * 20 = -0.1010001 * 24
Previous examples, in IEEE 794
format
0.25 = 0.01 * 20 =
00000000001000000000000000000000
-10.125 = -0.1010001 * 24 =
10000010010100010000000000000000