Converting integer to binary representation

Bengt Richter bokr at oz.net
Thu Dec 18 00:28:48 EST 2003


On 18 Dec 2003 05:07:23 GMT, bokr at oz.net (Bengt Richter) wrote:
[...]
>(not tested beyond what you see here ;-)
[...]
>            exclude = [
[...]
>                '__hash__', '__hex__', '__init__', '__int__', '__invert__', '__long__',
                                                                ^^^^^^^^^^
[...]
> >>> from lbits import LBits
> >>> b = LBits(11)
> >>> b, -b, ~b, b&5, b^5, b*4, b/2, str(b), repr(b)
             ^^
> (01011b, 10101b, -12L, 01b, 01110b, 0101100b, 0101b, '11', '01011b')
                   ^^^^
Didn't notice ;-/
 
>I'll leave full testing and better error messages and adding a divmod method and such as an exercise ;-)

There's undoubtedly more ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list