[Tutor] Hex to Str - still an open issue

Liam Clarke cyresse at gmail.com
Sat Feb 5 12:44:43 CET 2005


Jacob - just for you, begin your agitation for the next release please ;)

binstring.py, as attached. 
(also pasted up - http://www.rafb.net/paste/results/5feItM57.html)

Creating this, was just a brain teaser, but I was thinking 'what if I
wanted to make this for the standard library.'

And so you can see, I had to include a flag for endianess. But that
was really a cheap trick. If this was going into a standard library,
I'd want to query the OS for endianess. As for the bits, once again,
32 bit is the norm, but 64 bit is here and spreading.

Also, should it display 11111111 as 255 or 256? Both are valid,
depending on context.

Thirdly, if I can do it in 2 minutes, (well, the main part), then
should they bother putting it in the standard library considering
also,

- How often, really, are you going to need to present a decimal or hex
as a binary string.

Lastly - this only does base 10 to base 2. Should I include a base 6
to base 2, base 8 to base 2, base 10 to 6, 10 to 8, 8 to 6?

I wouldn't like to write for the standard library, because you can
never please everyone.

But yeah, feel free to use the above, just keep my doc strings and comments.

Regards,

Liam Clarke

On Fri, 4 Feb 2005 23:30:19 -0500, Jacob S. <keridee at jayco.net> wrote:
> > The binary value is the same as the hex value.
> > The binary representation is 000111110100, but
> > unfortunately Python doesn't support binary in
> > its string formatting(although it does in int()!
> 
> Uh, question. Why not? It seems that all simple types should be included.
> Since the computer stores it as binary, why shouldn't python be able to
> display a
> string of it in binary? That seems to be a short coming that should be added
> to the
> next release... IMHO of course.
> Jacob Schmidt
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: binstring.py
Type: text/x-python
Size: 1107 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20050206/28f6f80e/binstring.py


More information about the Tutor mailing list