[Tutor] Offtopic Reply, was: Negative Signed Binary Conversion
Eric Brunson
brunson at brunson.com
Tue Oct 23 01:30:10 CEST 2007
You know, Alan, I remember you commenting that you had some flakey
behavior from this list a few of weeks ago, then
over the weekend I received about two dozen emails from threads as far
back as August.
Something is definitely wonky (technical term ;-) about this list server.
Alan Gauld wrote:
> <ddm2 at sfu.ca> wrote
>
>
>> I'm trying to get this binary converter working, but I can't seem to
>> get the
>> negatives to work properly.
>>
>
> I already sent a reply on this, but:
>
>
>> def conversion(n):
>> b = ''
>> while n > 0:
>>
>
> This line means you only ever return an empty string for a negative
> n...
>
>
>> n = int(raw_input("Please enter a signed integer: "))
>> bits = int(raw_input("Please enter the number of bits: "))
>> count = conversion(n).count("0") + conversion(n).count("1")
>>
>
> And you call it with anegative n here and use the empty
> string to calculate the count... => 0.
>
> HTH,
>
>
>
More information about the Tutor
mailing list