C++ program of finding binary value

In this program we will find the binary value of decimal numbers

//CODE Starts

#include<iostream>
#include <conio.h>
using namespace std;

int main()
{
int n,x,a, c, k;

cout<<“Enter an integer in decimal number system (0-9) : “;
cin>>x;
n=x;
cout<<“Binary Value OF Given Number Is: “;

for( a=1;n!=0;a++)
{
n=n/2;
}

a=a-2;

for (c = a; c >= 0; c–)
{
k = x >> c;
if (k & 1)

{

cout<<“1”;

}

else

{

cout<<“0”;
}

}
getch();
}

//CODE Ends

 

OUTPUT:

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s