Bit Operations
John Machin
sjmachin at lexicon.net
Wed Nov 28 16:49:56 EST 2007
On Nov 29, 8:05 am, "Gianmaria Iaculo - NVENTA"
<gianma... at hotmail.com> wrote:
> Txs all,
> i wont to respond to who asked why i needed it:
>
> I'm using python on GSM modules and the informations i have to move goes
> along GPRS/UMTS connections so it's beatiful for me to transfer more
> informations with less space...
> imagine i have to send this simple data....
>
> 41.232323,12.345678
>
> i can send it as it's or use the nibble trick and on the receiving station
> 'unlift" the data and rebuild the original information...
>
> isn'it???
Sorry, but it's not apparent what you propose to do. If each number
has 8 decimal digits of precision (as in your example), you could
possibly get by with a 32-bit floating point number. If it's always 6
decimal places and 0 <= number < 1000, you could pack (number *
1000000) into a 32-bit integer. For the above two options, check out
the struct module. OTOH, maybe it's "packed decimal" that you mean --
try Googling that phrase and see if it matches your intentions. If it
does, and you are concerned with speed, a 100-element dictionary
mapping each byte-pair to a packed byte might be a good idea instead
of the bit bashing:
convert = {
'78': '\x78',
...
}
See http://mail.python.org/pipermail/python-list/2000-October/056329.html
HTH,
John
More information about the Python-list
mailing list