On 20/04/2015 21:47, Ben Finney wrote:
Jim Mooney writes:
I can't seem to get my head around this 'simple' book example of
binary-to-decimal conversion, which goes from left to right:
B = '11011101'
I = 0
while B:
I = I * 2 + int(B[0])
B = B[1:]
print(I)
221
That is, IMO, a need
On 04/20/2015 04:15 PM, Jim Mooney wrote:
The key is that the result gets multiplied by 2 each time
so for an N bit number the leftmost digit winds up being
effectively 2**N, which is what you want.
Alan G
Ah, the light dawns once it was restated. It would be even simpler if you
could
The key is that the result gets multiplied by 2 each time
> so for an N bit number the leftmost digit winds up being
> effectively 2**N, which is what you want.
>
> Alan G
Ah, the light dawns once it was restated. It would be even simpler if you
could multiply each element of the binary numbe
Jim Mooney writes:
> I can't seem to get my head around this 'simple' book example of
> binary-to-decimal conversion, which goes from left to right:
>
> B = '11011101'
> I = 0
> while B:
> I = I * 2 + int(B[0])
> B = B[1:]
>
> print(I)
> >>> 221
That is, IMO, a needlessly confusing way t
On 20/04/15 17:58, Alex Kleider wrote:
The key is that the result gets multiplied by 2 each time
so for an N bit number the leftmost digit winds up being
effectively 2**N, which is what you want.
Shouldn't that be 2**(N-1)?
Yes, sorry.
--
Alan G
Author of the Learn to Program web site
http
On Mon, Apr 20, 2015 at 11:21 AM, Alan Gauld wrote:
>>
>> B = '11011101'
>> I = 0
>> while B:
>> I = I * 2 + int(B[0])
>> B = B[1:]
>
>> Both methods work but I just can't see how the first one does.
>
> The key is that the result gets multiplied by 2 each time
> so for an N bit number t
On 2015-04-20 09:21, Alan Gauld wrote:
On 20/04/15 08:44, Jim Mooney wrote:
I can't seem to get my head around this 'simple' book example of
binary-to-decimal conversion, which goes from left to right:
B = '11011101'
I = 0
while B:
I = I * 2 + int(B[0])
B = B[1:]
...
Both methods wo
On 20/04/15 08:44, Jim Mooney wrote:
I can't seem to get my head around this 'simple' book example of
binary-to-decimal conversion, which goes from left to right:
B = '11011101'
I = 0
while B:
I = I * 2 + int(B[0])
B = B[1:]
...
Both methods work but I just can't see how the first on
On 20 April 2015 at 08:44, Jim Mooney wrote:
> I can't seem to get my head around this 'simple' book example of
> binary-to-decimal conversion, which goes from left to right:
>
> B = '11011101'
> I = 0
> while B:
> I = I * 2 + int(B[0])
> B = B[1:]
Follow through the loop and see what ha
On Apr 20, 2015 6:56 AM, "Jim Mooney" wrote:
>
> I can't seem to get my head around this 'simple' book example of
> binary-to-decimal conversion, which goes from left to right:
>
> B = '11011101'
> I = 0
> while B:
> I = I * 2 + int(B[0])
> B = B[1:]
>
> print(I)
> >>> 221
>
> My thought w
I can't seem to get my head around this 'simple' book example of
binary-to-decimal conversion, which goes from left to right:
B = '11011101'
I = 0
while B:
I = I * 2 + int(B[0])
B = B[1:]
print(I)
>>> 221
My thought was to go from right to left, multiplying digits by successive
powers of
11 matches
Mail list logo