Convert a given Binary number into Decimal Number Using Bitwise Operators - C Language Programming

Convert a given binary number by user into a equivalent decimal number using bitwise operators



Click here to open this program in Turbo C++

/**********************************************************
 Statement - Convert number to binary using bitwise operators
 Programmer - Vineet Choudhary
 Written For - http://developerinsider.co
 **********************************************************/

#include<stdio.h>
#include<conio.h>

//Display integer number into binary using bitwise operator
void printBinary(int num)
{
    int mask = 0x4000;
    if ((num & 0x8000) == 0)
        printf("0");
    else
        printf("1");
    while (mask != 0) {
        if ((num & mask) == 0)
            printf("0");
        else
            printf("1");
        mask = mask >> 1;
    }
}

void main()
{
    int intNum;
    clrscr();
    
    printf("\nEnter a integer number :");
    scanf("%d", &intNum);
    
    printf("\nInteger number in binary format :");
    printBinary(intNum);
    
    getch();
}

You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.