Unpacking a hex value
Chris Liechti
cliechti at gmx.net
Fri May 17 22:54:08 EDT 2002
Matthew Diephouse <fokke_wulf at hotmail.com> wrote in
news:3CE5BD65.3000908 at hotmail.com:
> The code is very much like the Perl code I submitted. It is within a
> subroutine.
>
> def hex2bin(input)
> output = hex( input )
> output = pack("!l", output)
> ...
if you want to convert a number to a string containing the binary
represenation of the number try it without hex():
def hex2bin(inp)
output = pack("!l", inp)
...
hex() in python converts number->string. if the input above is a string
with hexdigits use int() instead:
output = pack("!l", int(inp,16))
or if you need to cut away '0x'
output = pack("!l", int(inp[2:],16))
chris
> From this, I get the error "required argument is not an integer", as
> previously stated. There's no other info in the Traceback that's
> important. I've tried wrapping output with a call to the int() function,
> but that doesn't work either.
>
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list