Re: [Tutor] Binary to Decimal conversion

2009-03-10 Thread Alan Gauld
"A.T.Hofkamp" wrote If you reverse the computation, it gets even simpler: binstr = raw_input("Please enter a binary number: ") decnum = 0 for i in binstr: decnum = decnum * 2 + int(i) But if we are allowed to use int() it is easier still: decnum = int(raw_input("Please enter a binar

Re: [Tutor] Binary to Decimal conversion

2009-03-10 Thread A.T.Hofkamp
Hello, Chris Castillo wrote: Thanks for clearing that up. I knew it was much simpler than I was trying to make it I just couldn't quite see the logic that I needed for the problem clearly. Thanks for the elegant code. On Mon, Mar 9, 2009 at 10:53 PM, Moos Heintzen wrote: binnum = raw_input("

Re: [Tutor] Binary to Decimal conversion

2009-03-10 Thread Chris Castillo
Thanks for clearing that up. I knew it was much simpler than I was trying to make it I just couldn't quite see the logic that I needed for the problem clearly. Thanks for the elegant code. On Mon, Mar 9, 2009 at 10:53 PM, Moos Heintzen wrote: > You're making it more complicated than it needs to.

Re: [Tutor] Binary to Decimal conversion

2009-03-09 Thread Moos Heintzen
You're making it more complicated than it needs to. Also, you first used binnum then binum, and you didn't define binsum. It could easily be done like this: binnum = raw_input("Please enter a binary number: ") decnum = 0 rank = 1 for i in reversed(binnum): decnum += rank * int(i) rank *

Re: [Tutor] Binary to Decimal conversion

2009-03-09 Thread bob gailer
Chris Castillo wrote: I am having some difficulties in producing the correct code for a simple binary to decimal conversion program. The arithmetic I want to use is the doubling method - so if I wanted to get the decimal equivalent of 1001, I would start with multiplying 0 * 2 and adding the l

Re: [Tutor] Binary to Decimal conversion

2009-03-09 Thread bob gailer
Chris Castillo wrote: I am having some difficulties in producing the correct code for a simple binary to decimal conversion program. The arithmetic I want to use is the doubling method - so if I wanted to get the decimal equivalent of 1001, I would start with multiplying 0 * 2 and adding the l

[Tutor] Binary to Decimal conversion

2009-03-09 Thread Chris Castillo
I am having some difficulties in producing the correct code for a simple binary to decimal conversion program. The arithmetic I want to use is the doubling method - so if I wanted to get the decimal equivalent of 1001, I would start with multiplying 0 * 2 and adding the left most digit. I would the