[Python-3000] New built-in function: bin()

Guido van Rossum guido at python.org
Fri Apr 21 13:02:41 CEST 2006


This has been brought up many times before. The value of bin() is
really rather minimal except when you're just learning about binary
numbers; and then writing it yourself is a useful exercise.
I'm not saying that bin() is useless -- but IMO its (small) value
doesn't warrant making, maintaining and documenting a new built-in
function.
--Guido
On 4/21/06, Mike Traynar <mike_traynar at credence.com> wrote:
> I've always wondered why there isn't a bin() built-in in Python.
> Built-in functions already exist for converting ints to hexadecimal and
> octal strings and vice versa i.e.
>> s = hex() and int(s, 16)
> s = oct() and int(s, 8)
>> but no bin() function for binary strings
>> s = ??? and int(s, 2)?
>> Working with hardware I occasionally need to display an integer in
> binary format, or manipulate the bits of integer. A simple example would
> be reversing the order of the bits. Converting an int to binary string,
> reversing the string, then converting back to an int is a simple way to
> do this. Right now I use the recipe in
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/219300 and am
> happy to continue to do so, but it has always struck me as odd that
> there isn't a bin() built-in.
>> Mike
>> PS. I'll let someone else argue the case for the tri(), quad(),
> penta()... built-in functions.
>>> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>
--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list

AltStyle によって変換されたページ (->オリジナル) /