How to convert from decimal to binary?
Calculation Steps for the Integer part:
- Divide the decimal number by 2.
- Get the integer quotient and use it for the next iteration.
- Get the remainder and use it for the binary digit.
- Repeat the above steps until the quotient is equal to 0, or after a specified number of steps.
Steps to calculate the fractional part:
- Multiply the fractional part by 2.
- Take the integer part of the product as the fraction digit. Take the fractional part of the product for the next iteration.
- Repeat the steps above until the fractional part becomes 0, or stop after a number of steps if the fractional part does not become 0.
Example:
Convert 15.37510 to binary:
Convert the integer part:
| Divide by 2 | Quotient | Remainder | Bit |
|---|
| 15/2 | 7 | 1 | 0 |
| 7/2 | 3 | 1 | 1 |
| 3/2 | 1 | 1 | 2 |
| 1/2 | 0 | 1 | 3 |
Convert the fraction part:
| Multiply by 2 | Product | Remainder | Fraction Digit |
|---|
| 0.375*2 | 0.75 | 0.75 | 0 |
| 0.75*2 | 1.5 | 0.5 | 1 |
| 0.5*2 | 1 | 0 | 1 |
Result: 15.7510 = 1111.0112