Hi I have an binary of 10 bits . How do i change it to decimal

suppose binary is 1000000001 . I need to get the decimal of it . Can some body gimme the psedocode??

So figure out how you turn "1234" into an integer on paper.

"1234"(decimal) is 1234
"1234"(octal) is 668

It's just a loop of extracting the numeric value of each digit (say '3' into 3), and multiplication by the base (10, 8, 2 or whatever).

Ok try this,

int x[11];
int i=11,decimal=0;
for(i=0;i<11;i++)
/*here to allow the user to enter 11 binary numbers*/
scanf("%d",&x);

for(i=10;i>=0;i--)
{
if(a==1)
decimal= decimal + 2 * i ;

}

printf("your decimal number is %d",decimal);

please reply to me if it is correct thanks

int x[11];
int i=11,decimal=0;
for(i=0;i<11;i++)
/*here to allow the user to enter 11 binary numbers*/
scanf("%d",&x[i]);

for(i=10;i>=0;i--)
{
if(a[i]==1)
decimal+=2 * i ;

}

printf("your decimal number is %d",decimal);

It is working....:cool:

sorry jokerjokerer what I have done is not correct How!!!!.
let's say we have this binary number00000000001 by the privous programming gives the result equal to 2048 and that is wrong the correct decimal is 1 not 2048 . therefore I would correct my answer by the following programe

and please if you get it reply to me thanks

#include<stdio.h>
#include<math.h>
int main()
{
int k=-1,i=0,decimal=0;
int a[11];
printf("please enter 11 binary numbers");
for(i=0;i<11;i++)
//to allow user enter 11 binary numbers
scanf("%d",&a);
if(a==1)
{
k++;
decimal+=power(2,k);
}
else
k++;

return 0;
}
//please as soon as you get it tell me that.
// sorry for my mistak

sorry I missed the for looping after the scanf
for(i=10;i>=0;i--){
// put here the program as mentioned above
}

return 0;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.