156649415 binary to decimal
DESCRIPTION
Binary To Decimal Enjoy!!!TRANSCRIPT
Binary to decimal
In base 2 all digits are either 0 or 1 and can be interpreted as
10111 = 1 x 1 + 1 x 2 + 1x 4 + 0 x 8 + 1 x 16
=1 x 20 +1 x 21 + 1 x 22 +0 x 23 +1 x 24 = 23( base 10)
If b is an array containing these 5 digits so that b[0]=1, b[1]=1, b[2]=1,b[3]=0, b[4]=1, how do we write code to get to the decimal equivalent?
Inefficient Binary to decimal code
#include
#include
int main()
{
/* to convert a binary representation to a decimal one*/
int dec=0,b[5]={1,1,1,0,1};
for (int i=0;i