digit to binary conversion in cpp

technical talkiess
0

// Online C++ compiler to run C++ program online

#include <iostream>

#include <math.h>

using namespace std;

int main() {

    int a;

    cout<<"Enter the number";

    cin>>a;

    int answer = 0;

    int i =0;

    while(a!=0){

      int bit = a & 1;

      answer = (bit * pow(10,i)) + answer;

      a = a>>1;

      i++;

    }

     cout<<answer;

    return 0;

}

Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)