User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,501 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,671 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 1286 | Replies: 9
Reply
Join Date: Sep 2007
Posts: 1
Reputation: srikanth329 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
srikanth329 srikanth329 is offline Offline
Newbie Poster

converting binary to decimal

  #1  
Sep 21st, 2007
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??
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: converting binary to decimal

  #2  
Sep 21st, 2007
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).
Reply With Quote  
Join Date: Mar 2007
Location: Israel
Posts: 16
Reputation: Shaffer is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Shaffer Shaffer is offline Offline
Newbie Poster

Re: converting binary to decimal

  #3  
Sep 21st, 2007
Here, Google's wonders:
http://mistupid.com/computers/binaryconv.htm

Or do you want the source code to that?
Reply With Quote  
Join Date: Jan 2007
Location: Istanbul / Turkey
Posts: 22
Reputation: VatooVatoo is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
VatooVatoo's Avatar
VatooVatoo VatooVatoo is offline Offline
Newbie Poster

Re: converting binary to decimal

  #4  
Sep 21st, 2007
Reply With Quote  
Join Date: Aug 2007
Posts: 22
Reputation: alsoumhi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
alsoumhi alsoumhi is offline Offline
Newbie Poster

Re: converting binary to decimal

  #5  
Sep 26th, 2007
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[i]);

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

}

printf("your decimal number is %d",decimal);
Reply With Quote  
Join Date: Aug 2007
Posts: 22
Reputation: alsoumhi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
alsoumhi alsoumhi is offline Offline
Newbie Poster

Re: converting binary to decimal

  #6  
Sep 26th, 2007
please reply to me if it is correct thanks
Reply With Quote  
Join Date: Sep 2007
Location: Tirgu-Mures Romania
Posts: 10
Reputation: jokerjokerer is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jokerjokerer's Avatar
jokerjokerer jokerjokerer is offline Offline
Newbie Poster

Solution Re: converting binary to decimal

  #7  
Sep 26th, 2007
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....
Change your thought and the world around you changes.
"In a moment, everything can change. Feel the wind on your shoulders.
For a minute, all the world can wait. Let go of your yesterday. " H.Duff-Fly

Anything is possible
Reply With Quote  
Join Date: Apr 2004
Posts: 3,755
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: converting binary to decimal

  #8  
Sep 26th, 2007
Reply With Quote  
Join Date: Aug 2007
Posts: 22
Reputation: alsoumhi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
alsoumhi alsoumhi is offline Offline
Newbie Poster

Re: converting binary to decimal

  #9  
Sep 27th, 2007
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[i]);
if(a[i]==1)
{
k++;
decimal+=power(2,k);
}
else
k++;

return 0;
}
//please as soon as you get it tell me that.
// sorry for my mistak
Reply With Quote  
Join Date: Aug 2007
Posts: 22
Reputation: alsoumhi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
alsoumhi alsoumhi is offline Offline
Newbie Poster

Re: converting binary to decimal

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

return 0;
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 3:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC