Converting an integer to base 2
David R. Smith
drs at alex2.labs.agilent.com
Fri Nov 30 14:01:39 EST 2001
More information about the Python-list mailing list
Fri Nov 30 14:01:39 EST 2001
- Previous message (by thread): Python 2.2b1 dicts, iteration, and subclassing
- Next message (by thread): Converting an integer to base 2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
int(string, 2) converts the string to the internal representation. You
told it that the string was base-2, e.g., '101'. '5' is not a valid
digit in binary.
Stephen Boulet wrote:
>
> I'm trying to convert integers to base 2. Can someone tell me why this
> doesn't work?
>
> >>> int('5', 2)
> Traceback (most recent call last):
> File "<pyshell#102>", line 1, in ?
> int('5', 2)
> ValueError: invalid literal for int(): 5
>
> Thanks.
>
> -- Stephen
- Previous message (by thread): Python 2.2b1 dicts, iteration, and subclassing
- Next message (by thread): Converting an integer to base 2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list