Java Reference
In-Depth Information
APPENDIX D
A
DDITIONAL
J
AVA
T
OPICS
Integer
Chapter 1 noted that
A
is the 66th character in the ASCII character set, but its position
is 65 because the position of the first character is
0
. Furthermore, the binary number
1000001
is the binary representation of
65
. The number system that we use daily is called
the decimal number system or base 10 system. The number system that the computer
uses is called the binary number system or base 2 system. In this section, we describe
how to find the binary representation of a nonnegative integer and vice versa.
Consider 65. Note that:
65
¼
1
2
6
þ
0
2
5
þ
0
2
4
þ
0
2
3
þ
0
2
2
þ
0
2
1
þ
1
2
0
:
Similarly:
711
¼
1
2
9
þ
0
2
8
þ
1
2
7
þ
1
2
6
þ
0
2
5
þ
0
2
4
þ
0
2
3
þ
1
2
2
þ
1
2
1
þ
1
2
0
:
In general, if m is a nonnegative integer, then m can be written as:
m ¼ a
k
2
k
þ a
k
1
2
k
1
þ a
k
2
2
k
2
þþa
1
2
1
þ a
0
2
0
;
for some nonnegative integer k, and where a
i
¼
0 or 1, for each i
¼
0, 1, 2, . . ., k. The
binary number a
k
a
k
1
a
k
2
...a
1
a
0
is called the binary or base 2 representation of m.In
this case, we usually write:
m
10
¼ða
k
a
k
1
a
k
2
a
1
a
0
Þ
2
and say that m to the base 10 is a
k
a
k
1
a
k
2
...a
1
a
0
to the base 2.
949
Search WWH ::
Custom Search