C++ Program For Binary Equivalent Of A Decimal Number andrey суббота, 18 октября 2014 г. No Comment

The c++ program below finds the binary equivalent of an integer entered by the user in decimal form. The binary system often referred to as base two is made of only two digits which are o and 1. The decimal system as the most commonly used number system, has values ranging from 0 to 9. Normally, to convert a binary number to a decimal number, a division is made where the number is divided by 2 and the remainders either o or 1 are read from bottom to top.

Also Read: C++ Program to Compute The Least Common Multiple of Integers


Also Read: C++ Program to Compute The Least Common Multiple of Integers


C++ Program For Binary Equivalent Of A Decimal Number


#include
#include
int main()
{
int n,x,i, j, k;
cout<<"Enter an integer in the decimal number system: ";
cin>>n;
x=n; //assign the value entered for x to n
cout<<"Binary equivalent of the "<<x<<" "<<"is: ";
for( i=1;x!=0;i++)
{
x=x/2;
}
i=i-2;
for (j= i; j>= 0; j--)
{
k = n >> j;
if (k & 1)
cout<<"1";
else
cout<<"0";
}
return 0;
}

Also Read: C++ Program to Check If a Number Is A Perfect Number or Not

The c++ program below finds the binary equivalent of an integer entered by the user in decimal form. The binary system often referred to as base two is made of only two digits which are o and 1. The decimal system as the most commonly used number system, has values ranging from 0 to 9. Normally, to convert a binary number to a decimal number, a division is made where the number is divided by 2 and the remainders either o or 1 are read from bottom to top.

Also Read: C++ Program to Compute The Least Common Multiple of Integers


Also Read: C++ Program to Compute The Least Common Multiple of Integers


C++ Program For Binary Equivalent Of A Decimal Number


#include
#include
int main()
{
int n,x,i, j, k;
cout<<"Enter an integer in the decimal number system: ";
cin>>n;
x=n; //assign the value entered for x to n
cout<<"Binary equivalent of the "<<x<<" "<<"is: ";
for( i=1;x!=0;i++)
{
x=x/2;
}
i=i-2;
for (j= i; j>= 0; j--)
{
k = n >> j;
if (k & 1)
cout<<"1";
else
cout<<"0";
}
return 0;
}

Also Read: C++ Program to Check If a Number Is A Perfect Number or Not

by Jillur Rahman

Jillur Rahman is a Web designers. He enjoys to make blogger templates. He always try to make modern and 3D looking Templates. You can by his templates from Themeforest.

Follow him @ Twitter | Facebook | Google Plus

No Comment