Binary numbers have only 2 symbols viz. 0 and 1, unlike the decimal system used in eveyday life, which has symbols from 0 to 9.
Lets take the decimal system for instance, all numbers in the decimal system are made up from the symbols from 0 to 9. Note it is called decimal system because we have 10 basic symbols(0,1,2,3,4,5,6,7,8,9) which make the full number system.
It starts with all the symbols individually i.e. 0 to 9, when we reach 9, we go to next level, i.e. 10. We go to the next level because we have reached the last number on the current level.
The same should be applied to the binary number system, but instead of 10 basic symbols we have only 2, viz. 0 and 1. As we did in the decimal system, we start of with the basic symbols are the number and then go to the next level, if we reach the last number of a level then again we go to the next level; below is the binary number system:
0
1
10 (Since 1 is the last number at the curret level, we goto the next level)
11
100 (Again since 11 was the last number at the current level, we goto the next level)
101
....
....
Sadly there is no binary data-type in C. So we will have to use the integer data-type which uses the decimal system. So we will need to convert decimal-number to binary logically.
The binary number equivalents for all decimal numbers can be found by, repeatively dividing numbers by 2 and then taking the remainders in reverse order.
(Note: Keep this method in mind, because we will use it for the approach.)
Let me illustrate with an example:
Consider decimal number 49, lets convert it to binary.
49/2 = 24 r 1
24/2 = 12 r 0
12/2 = 6 r 0
6/2 = 3 r 0
3/2 = 1 r 1
1/2 = 0 r 1
Now take the remainders in reverse order, this will give 49 in binary, i.e.:
110001.
If the above concepts are clear, then only I'll go-on to the approach(logic).