G.3. Converting Decimals

Converting Decimals to Binary Numbers

In order to convert decimals to binaries, we reverse the process outlined in Section G.1 for converting a binary to a decimal.

4110 =20×2+ 1Dividing 41 by 2, gives the quotient 20 and remainder 1.
2010 =10×2+ 0We again divide the current quotient 20 by 2.
1010 =5×2+ 0 
510 =2×2+ 1We repeat this procedure until ...
210 =1×2+ 0 
110 =0×2+ 1... the quotient is 0.
4110 =1010012

The divisor used in the steps above is the base of the target number system (binary, base 2). The binary value, 1010012, is represented by the remainders, with the last remainder as the left-most bit. Back substitution of the quotient gives the same result:

4110= (((((0×2 + 1)×2 + 0)×2 + 1)×2 + 0)×2 + 0)×2 + 1
 = 1×2 ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.