Java Reference
In-Depth Information
numbers work. To count with binary numbers, as with base-10 numbers, you start with 0
and count up, but you run out of digits much faster. So, counting in binary, you say
0
1
And already you've run out of digits. This is like reaching 9 when you count in
base-10. After you run out of digits, you carry over to the next digit. So, the next two
binary numbers are
10
11
And again, you've run out of digits. This is like reaching 99 in base-10. Again, you
carry over to the next digit to form the three-digit number 100. In binary, whenever
you see a series of ones, such as 111111, you know you're just one away from the
digits all flipping to 0s with a 1 added in front, the same way that, in base-10, when
you see a number like 999999, you know that you are one away from all those digits
turning to 0s with a 1 added in front.
Table 1.1 shows how to count up to the base-10 number 8 using binary.
Table 1.1
Decimal vs. Binary
Decimal
Binary
0
0
1
1
2
10
3
11
4
100
5
101
6
110
7
111
8
1000
We can make several useful observations about binary numbers. Notice in the
table that the binary numbers 1, 10, 100, and 1000 are all perfect powers of 2 (2 0 ,2 1 ,
2 2 ,2 3 ). In the same way that in base-10 we talk about a ones digit, tens digit, hun-
dreds digit, and so on, we can think in binary of a ones digit, twos digit, fours digit,
eights digit, sixteens digit, and so on.
Computer scientists quickly found themselves needing to refer to the sizes of differ-
ent binary quantities, so they invented the term bit to refer to a single binary digit and the
term byte to refer to 8 bits. To talk about large amounts of memory, they invented the
terms kilobytes (KB), megabytes (MB), gigabytes (GB), and so on. Many people think
that these correspond to the metric system, where “kilo” means 1000, but that is only
approximately true. We use the fact that 2 10 is appromixately equal to 1000 (it actually
equals 1024). Table 1.2 shows some common units of memory storage:
 
Search WWH ::




Custom Search