# Conversion of Decimal Number System into Binary Number System

Here, we are going to learn **how to convert Decimal Number System into Binary Number System?**

Submitted by Saurabh Gupta, on October 12, 2019

### Double Dabble Method

In this method, the **decimal integer number is converted to a binary integer** by successive division by 2, and the decimal fraction is **converted to a binary fraction** by successive multiplication by 2.

The decimal integer number is successively divided by 2 until the quotient is 0. The last remainder is the MSB. The remainders read starting from the bottom to the top give the equivalent binary integer number.

The decimal fractional number is successively multiplied by 2, till the fractional part of the product is 0. The first integer obtained is the MSB, thus the integers read from top to bottom gives the equivalent binary fraction.

To convert a mixed number to binary, we have to convert the integer and fractional part to binary separately and then combine them.

**Example 1:**

**Convert (13.25) _{10} to ( ? )_{2}**

**Solution:**

In 13.25, we have 13 as the integral part and 0.25 as the fractional part. To get an equivalent binary number, we have to convert both to binary separately and then combine them.

**Integral Part**

Divisor | Quotient | Remainder |
---|---|---|

2 | 13 | |

2 | 6 | 1 LSB |

2 | 3 | 0 |

2 | 1 | 1 |

2 | 0 | 1 MSB |

All the remainders read from top to bottom, where topmost is the LSB and bottom one is the MSB.

**Therefore, (13) _{10} = (1101)_{2}**

**Fractional Part**

0.25 * 2 = 0.50 MSB 0.50 * 2 = 1.00 LSB

Integer part of the product term read from top to bottom.

**Therefore, (0.25) _{10} = (0.01)_{2}**

Now, we can combine both the integral part and the fractional part to get the required binary equivalent i.e., **(13.25) _{10} = (1101.01)_{2}**

**Example 2:**

**Convert (15.6) _{10} to ( ? )_{2}**

**Solution:**

Converting Integral and Fractional part separately.

**Integral Part**

Divisor | Quotient | Remainder |
---|---|---|

2 | 15 | |

2 | 7 | 1 LSB |

2 | 3 | 1 |

2 | 1 | 1 |

2 | 0 | 1 MSB |

All the remainders read from top to bottom, where topmost is the LSB and bottom one is the MSB.

**Therefore, (15) _{10} = (1111)_{2}**

**Fractional Part**

0.6 * 2 = 1.2 MSB 0.2 * 2 = 0.4 0.4 * 2 = 0.8 0.8 * 2 = 1.6 0.6 * 2 = 1.2 0.2 * 2 = 0.4 0.4 * 2 = 0.8 0.8 * 2 = 1.6 LSB

Integer part of all the product terms read from top to bottom.

**Therefore, (0.6) _{10} = (0.1001)_{2}**

Now, we can combine both the integral part and the fractional part to get the required binary equivalent i.e., **(15.6) _{10} = (1111.1001)_{2}**

**Note:** If the numbers are non-terminating and non-repeating then, in that case, the process of multiplication is to be stopped after 4 or 5 decimal places.

**Example 3:**

**Convert (18.75) _{10} to ( ? )_{2}**

**Solution:**

In 18.75, 18 is the integral part and 0.75 is the decimal part. To convert 18.75 into binary we first have to convert integral and fractional part individually and then combine them together.

**Integral Part**

Divisor | Quotient | Remainder |
---|---|---|

2 | 18 | |

2 | 9 | 0 LSB |

2 | 4 | 1 |

2 | 2 | 0 |

2 | 1 | 0 |

2 | 0 | 1 MSB |

All the remainders read from top to bottom, where topmost is the LSB and bottom one is the MSB.

**Therefore, (18) _{10} = (10010)_{2}**

**Fractional Part**

0.75 * 2 = 1.50 MSB 0.50 * 2 = 1.00 LSB

Integer part of all the product terms read from top to bottom.

**Therefore, (0.75) _{10} = (0.11)_{2}**

Now, we can combine both the integral part and the fractional part to get the required binary equivalent i.e., **(18.75) _{10} = (10010.11)_{2}**

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.