Java Reference
In-Depth Information
100 Ö 2 = 50 remainder 0
50 Ö 2 = 25 remainder 0
25 Ö 2 = 12 remainder 1
12 Ö 2 = 6 remainder 0
6 Ö 2 = 3 remainder 0
3 Ö 2 = 1 remainder 1
1 Ö 2 = 0 remainder 1
Therefore, 100 in decimal is 1100100 in binary.
To convert a fractional number <1 to its binary format, keep multiplying by 2. If
the result is >1, subtract 1. Stop when the number is 0. Then use the digits before
the decimal points as the binary digits of the fractional part, starting with the first
one. For example,
0.35 – 2 = 0 .7
0.7 – 2 = 1 .4
0.4 – 2 = 0 .8
0.8 – 2 = 1 .6
0.6 – 2 = 1 .2
0.2 – 2 = 0 .4
Here the pattern repeats. That is, the binary representation of 0.35 is 0.01 0110
0110 0110 ș
To convert any floating-point number into binary, convert the whole part and the
fractional part separately. For example, 4.35 is 100.01 0110 0110 0110 ș in
binary.
You don't actually need to know about binary numbers to program in Java, but at
times it can be helpful to understand a little about them. For example, knowing that
an int is represented as a 32-bit binary number explains why the largest integer
Search WWH ::




Custom Search