A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-August/048467.html below:

[Python-Dev] os.urandom API

[Python-Dev] os.urandom APIJosiah Carlson jcarlson at uci.edu
Mon Aug 30 05:48:49 CEST 2004
(Quick apology to Tim for accidentally sending this to him only, I 
recently switched email clients and am still getting used to it)

> Note that it's easy (abeit obscure) to generate a long from a string s:
> 
>     long(binascii.hexlify(s), 16)

or even:
     long(s.encode('hex'), 16)


> It's harder to go in the other direction.  First you do hex(n). Then

Perhaps what is needed is a method to easily convert between large 
integers and strings.  It seems as though a new struct conversion code 
is in order, something that works similarly to the way the 's' code works:

#pack the integer bigint as a signed big-endian packed binary string,
#null-filling as necessary, for 64 bytes of precision
a = struct.pack('>64g', bigint)

#unpack an unsigned little-endian packed binary string of 24 bytes to a 
#python long
b = struct.unpack('<24G', a)


With such a change, I think many of the string/integer translation 
complaints would disappear.

  - Josiah

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4