"Johan Geldenhuys" <[EMAIL PROTECTED]> wrote
> On the struct module, How can I het the binary 1's
> and 0's of the Hex value? Let say I want to get the
> 8 bit value of '\xe2', can I use struct to convert
> that into binary code
No, struct converts your data into a string of bytes and
provid
Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of David Perlman
Sent: 19 February 2007 05:56 PM
To: tutor@python.org
Subject: Re: [Tutor] Struct the solution for Hex translation
You're way off base... :)
On Feb 19, 2007, at 9:25 AM, Johan Geldenhuys wrote
"Johan Geldenhuys" <[EMAIL PROTECTED]> wrote
>>> data
'\xa5\x16\x0b\x0b\x00\xd5\x01\x01\x01\x00\x00\xe3\x84(\x01\xc6\x00\x00\x17\x
01C\xc7'
>>> data[0]
'\xa5'
>>> len(data[0])
1
>>>
OK, So that tells you that you have one byte.
The '\xa5' is a 4 character representation of that byte but it
is on
You're way off base... :)
On Feb 19, 2007, at 9:25 AM, Johan Geldenhuys wrote:
> Here is what I have:
>
data
> '\xa5\x16\x0b\x0b\x00\xd5\x01\x01\x01\x00\x00\xe3\x84(\x01\xc6\x00
> \x00\x17\x
> 01C\xc7'
data[0]
> '\xa5'
len(data[0])
> 1
>
> You see that data[0] is only one by
101", "e" : "1110", "f" : ""
}
>>> def hexBin(hexchars):
... s = ""
for hexchar in hexchars:
s += hex2bin[hexchar]
return s.rstrip("\n")
...
>>> hexBin('a5')
'1010
"Johan Geldenhuys" <[EMAIL PROTECTED]> wrote
> The first two bytes of the data is a 16 bit value. Eg: "\xe2\x01'
>
> I can the first byte into binary if I use 'e2', but I don't know
> how to get the '\x' out of the first byte to use it in python.
Are you sure it is there?
Usually the \x is o
Hi all,
I read in some conversations that the struct module maybe helpful in
converting Hex values to binary or decimal. Maybe I understood it
incorrectly.
Here is my problem.
I have a 22 byte data packet on a tcp socket connection. My data field is
from the 6th byte to byte 20. 14 bytes in t