Pages

Monday, 13 July 2015

Decimal to Binary

C Program to Convert Decimal to Binary
Coding:
#include<stdio.h>
int main()
{
    int i,n;
    printf("Please enter the number:");
    scanf("%d",&n);
    printf("Binary equivalent in %d bit:",sizeof(n)*8);
    for(i=sizeof(n)*8-1;i>=0;i--)
        printf("%d",(n>>i)&1);
    return 0;
}

Output:
Please enter the number:45
Binary equivalent in 16 bit:0000000000101101