Proposal for a generic showIntAtBase
Henning Thielemann
lemming at henning-thielemann.de
Mon Apr 6 19:04:33 UTC 2015
On Mon, 6 Apr 2015, Jon Purdy wrote:
> Could you offer a specific use case? When I need to convert a number
> to its representation in some base, it’s because I’m displaying or
> serialising it. A base is a notation (or a variant of a notation) and
> it seems sensible to represent such notations with characters.
E.g. you can use it to pack a tuple of small integers space efficiently
into a larger integer type. E.g. you can pack 3 integers from the range
0..4 into 7 bits using a base-5 representation, but you would need 9 bits
if you reserve three bits for every small integer.
Using the positional representation you can also convert between tupled
and linear indexes of an array with equal extents in all dimensions (i.e.
a hypercube).
Both examples also work with mixed-base representations.
More information about the Libraries
mailing list