CS485G Spring 2015 4
(h) There are tools to help you detect referencing errors (such as
valgrind).
5 Binary representation
1. Bits are represented by two voltages, one for 0 and another for 1. A
typical representation would be .3V for 0 and 3.0V for 1, but every
architecture bases the values on the particular kind of transistors it
uses. When a voltage changes from one value to the other, there is
an intermediate time at which its value is indeterminate; hardware
carefully avoids inspecting the voltage then.
2. We usually think of numbers in decimal (base 10), but for systems
programming, we sometimes need to use binary (base 2) or hexadec-
imal (base 16) representation.
(a) Base 2 uses only digits 0 and 1. Represent, for instance, 5.25 as
101.01
2
. Some numbers can be represented exactly in decimal
but not in binary: 5.3 = 101.0100110011...
2
.
(b) Base 16 uses digits 0 . . . 9, A, B, C, D, E, F. The letters are usually
written in capital letters. Each hex digit corresponds to four bits.
285.3 = 11D.4CCCCCCCC
16
. . .
3. A byte is usually 8 bits. (The official name, used in computer
networks, is octet, but we’ll just say “byte”). When treated as
an unsigned integer, a byte has values ranging from 0 to 255 (or
11111111
2
= FF
16
).
4. Signed integers using n bits can store numbers in the
range −2
n−1
. . . 2
n−1
− 1. For n = 32, the range is
−2147483648 . . . 2147483647 or (−80000000
16
. . . 7FFFFFFF
16
).
5. It’s pretty easy to see how many distinct values you can store in n
bits. Since every bit can be 0 or 1, there are 2
n
possibilities. Luckily,
2
10
≈ 10
3
, so 2
32
= 2
2
× 2
30
= 4 × (2
10
)
3
≈ 4 × (10
3
)
3
= 4 × 10
9
= 4
billion. Or just remember that
2
10
= 1024 ≈ 10
3
= 1 thousand (kilo or K);
2
20
= 1048576 ≈ 10
6
= 1 million (mega or M);
2
30
= 1073741824 ≈ 10
9
= 1 billion (giga or G);
2
40
≈ 10
12
= 1 trillion (tera or T);
2
50
≈ 10
15
= 1 quadrillion (peta or P);
So 2
32
= 4G.
Kommentare zu diesen Handbüchern