How to convert a decimal number to binary and hexadecimal
Converting a decimal integer to another base requires repeated division by the target base (2 for binary, 16 for hexadecimal). The remainders of these divisions, read in reverse order, form the converted number.
This method applies to any positive integer conversion from base-10 to an arbitrary target base.
The setup
Identify the decimal integer and the target base . For binary, . For hexadecimal, . Prepare a two-column workspace to record successive quotients and remainders.
The steps
- Divide the decimal number by the base using integer division.
- Record the integer quotient and the remainder.
- Replace with the new quotient.
- Repeat steps 1-3 until the quotient becomes 0.
- Read the remainders from bottom to top (last remainder computed is the most significant digit).
- For hexadecimal, convert any remainders from 10 to 15 into letters: .
Checking the result
Multiply each digit of your result by , where is the zero-indexed position of the digit starting from the right. Sum these products. The total must equal your original decimal number .
Common errors
Reading the remainders top-to-bottom instead of bottom-to-top, resulting in a reversed string. Forgetting to map hexadecimal remainders to . Stopping the division process when the quotient is 1 instead of continuing until it is exactly 0.
Worked example
Convert the decimal number to binary and hexadecimal.
Binary Conversion () remainder remainder remainder remainder remainder remainder remainder remainder Reading bottom to top, the binary representation is .
Hexadecimal Conversion () remainder remainder Convert remainders to hex digits: , . Reading bottom to top, the hexadecimal representation is .
FAQ
Run your own problem
References: Digital Design by M. Morris Mano · Computer Organization and Design by David A. Patterson and John L. Hennessy
See also