C Program to Convert Decimal Numbers to Binary Numbers
Decimal number system is a base 10 number system using digits for 0 to 9 whereas binary number system is base 2 and uses 0 and 1. Given a decimal number as input from user we have to print the binary equivalent of input number.
For Example
- Divide the input decimal number by 2 and store the remainder.
- Store the quotient back to the input number variable.
- Repeat this process till quotient becomes zero.
- Equivalent binary number will be the remainders in above process in reverse order.
For Example
Suppose input decimal number is 13
Step 1. 13/2 , Remainder = 1, Quotient = 6
Step 2. 6/2 , Remainder = 0, Quotient = 3
Step 3. 3/2 , Remainder = 1, Quotient = 1
Step 4. 1/2 , Remainder = 1, Quotient = 0
Now, the Binary equivalent of 13 is the remainders in reverse order : 1101