Posted By:
23 Jun, 2013 1:12 pm PDT

Decimal to Binary in C

How to convert a decimal number to a binary number?

This code converts an integer from a decimal number system (base-10) to binary number system (base -2). The size of integer is assumed to be 32 bits. We can use bitwise operators to perform the task. We right shift the original number by one i.e. 31,30,29,.1,0 bits using a loop and bitwise AND the number obtained with 1. If the result is 1 then that bit is 1 else it is 0. The part of code is 

for (c = 31; c >= 0; c--)


    k = n >> c;


    if (k & 1)






Please see the video for more details�..

Was it useful?  

Please login to reply to this problem.

Related Problems on Fixoncloud