Message61148
I think it'd be useful with a built-in module (I
propose the name 'mint' :), providing classes for
emulating machine ints. There should be support for
ints of different sizes (at least 8, 16, 32, 64),
signedness and endianness. The machine ints would react
to overflow (negative values) and bit-level operations
in the same way their C equivalents would.
One idea for a feature would be a intobj.pack() (or
str() or whatever) method that could be used instead of
the struct module's pack(). int16(12345).pack() ->
"\x30\x39". int32(-1).pack() -> "\0xff\0xff\0xff\0xff",
etc.
A related idea is that these ints could provide slicing
to extract individual sets of bits or bytes. For
example, uint32()[8:16] could return an int (uint8?)
made from the bits in the int's second byte (whether
it's the second from the left or the right might be
fuzzy, I do realize).
Applications for this would be algorithmic code
involving bit fiddling (useful for cryptographic
applications, perhaps) and, obviously, programs that
have to operate on any binary data. It might also
resolve some issues related to the unification of longs
and ints. |
|
Date |
User |
Action |
Args |
2008-01-20 09:59:32 | admin | link | issue887237 messages |
2008-01-20 09:59:32 | admin | create | |
|