Best way to convert sequence of bytes to long integer
Alf P. Steinbach
alfps at start.no
Wed Jan 20 13:27:34 EST 2010
* Mark Dickinson:
> On Jan 20, 7:36 am, Steven D'Aprano <st... at REMOVE-THIS-
> cybersource.com.au> wrote:
>> I have a byte string (Python 2.x string), e.g.:
>>
>> s = "g%$f yg\n1\05"
>> assert len(s) == 10
>>
>> I wish to convert it to a long integer, treating it as base-256.
>
> By the way, are you willing to divulge what you're using this
> functionality for? When trying to hack out the API for int.to_bytes
> and int.from_bytes on the mailing list and bug tracker, some of the
> discussion about use-cases seemed a little too much like guesswork;
> I'd be curious to find out about real-life use-cases.
One possibility is that Steven wants to apply bitlevel and/or arithmetic
operations for e.g. some custom cryptographic thing. The string that he uses as
example is not completely unlike a message digest.
Another possibility is custom serialization/deserialization.
But it would be nice to know what it's actually about...
Cheers,
- Alf
More information about the Python-list
mailing list