hex -> 16bit signed int (newbie)
Steve Holden
sholden at holdenweb.com
Tue Apr 15 10:06:02 EDT 2003
"zif" <zf_acs at DELETETHIShotmail.com> wrote in message
news:TTRma.1502$KH1.321574 at news20.bellglobal.com...
> How can I get 16bit signed int from a hex string?
> Eval('0x...') gives me 16bit unsigned,
> struct.pack('i', '\x..\x..') works fine, but
> Python doesn't allow me to concatenate strings
> with '\' (str(92) gives me '\\', which doesn't
> work as well).
>
Here I assume your "str(92)" was a typo/thinko for "chr(92)". If this is
correct then you are clearly being misled by the way the interpreter
presents strings. If you think about it, it doesn't make sense for a call on
chr() to give anything other than a single-character string. Sure enough, a
closer check reveals exactly that:
>>> chr(92)
'\\'
>>> len(chr(92))
1
So the reason you *see* two slashes is because the interpreter escapes the
slash to give you a value that could be used in a Python program.
regards
--
Steve Holden http://www.holdenweb.com/
How lucky am I? http://www.google.com/search?q=Steve+Holden&btnI=1
Python Web Programming http://pydish.holdenweb.com/pwp/
More information about the Python-list
mailing list