[Patches] [ python-Patches-455076 ] %b format support for string/unicode

noreply@sourceforge.net noreply@sourceforge.net
Tue, 04 Dec 2001 11:32:51 -0800


Patches item #455076, was opened at 2001-08-24 13:00
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=455076&group_id=5470

Category: Core (C code)
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Greg Wilson (gvwilson)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: %b format support for string/unicode

Initial Comment:
This patch adds "%b" formatting of integer and long 
integer values to string and unicode objects.  A new 
built-in function 'bin()' (with behavior like 'oct()' 
and 'hex()') is also added.

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-04 11:32

Message:
Logged In: YES 
user_id=6380

I *could* reject this for incompleteness, because it doesn't
support binary literals. But instead I'll reject it for
overcompleteness. The occasional (IMO rare) desire to see
the binary representation of a number shouldn't require this
the standard library to schlepp along this much code (and if
I were to redesign Python today, oct() would be dropped too,
and hex() would have less standard support). It's a fun
exercise to write your own bin() function; here's mine:

| def bin(x):
|     if x == 0:
|         return '0'
|     if x < 0:
|         s = '-'
|         x = -x
|     else:
|         s = ''
|     L = []
|     while x:
|         L.append('01'[x&1])
|         x /= 2
|     L.append(s)
|     L.reverse()
|     return ''.join(L)


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=455076&group_id=5470