[EMAIL PROTECTED] wrote:
On Jun 24, 10:38 am, Mark Dickinson <[EMAIL PROTECTED]> wrote:
Interestingly, unlike hex and oct, bin doesn't add a trailing
'L' for longs:
bin(13L)
'0b1101'
I wonder whether this is a bug...
Strange in 2.6, but I know at least in 3.0 that all integers are C
eliben:
> Python's pack/unpack don't have the binary format for some reason, so
> custom solutions have to be developed. One suggested in the ASPN
> cookbook is:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286
> However, it is very general and thus inefficient.
Try mine, it may be fa
And:
# return as a string
def itob_string(integer, count = 8):
return "".join(str((integer >> i) & 1) for i in range(count - 1,
-1, -1))
# return as an iterator (i.e [0, 0, 0, 0, 1, 0, 1, 0])
def itob_list(integer, count = 8):
return [(integer >> i) & 1 for i in range(count - 1, -1, -1)]
On Jun 24, 10:38 am, Mark Dickinson <[EMAIL PROTECTED]> wrote:
> On Jun 24, 9:03 am, eliben <[EMAIL PROTECTED]> wrote:
>
> > What would be the quickest way to do this ? I think that for dec2bin
> > conversion, using hex() and then looping with a hex->bin lookup table
> > would be probably much fast
eliben <[EMAIL PROTECTED]> wrote:
> I'm interested in converting integers to a binary representation,
> string. I.e. a desired function would produce:
>
> dec2bin(13) => "1101"
>
> The other way is easily done in Python with the int() function.
>
> Perl has a very efficient way to do dec2bi
On Jun 24, 9:03 am, eliben <[EMAIL PROTECTED]> wrote:
> What would be the quickest way to do this ? I think that for dec2bin
> conversion, using hex() and then looping with a hex->bin lookup table
> would be probably much faster than the general baseconvert from the
> recipe.
I suspect you're righ
Le Tuesday 24 June 2008 10:03:58 eliben, vous avez écrit :
> Hello,
>
> I'm interested in converting integers to a binary representation,
> string. I.e. a desired function would produce:
>
> dec2bin(13) => "1101"
>
> The other way is easily done in Python with the int() function.
>
> Perl has a ver