declaring Hex in python

P

PythonAnimal

I want to use some old C code such as
#define GEN_STREAMTYPE_NULL 0x51
I need to send this to a server, but it must be declared as a unsigned
four byte constant. I can not just send a string. I love python, but
am looking for information where I can declare this and then send it
through a socket.
Also are there any classes or methods which can manipulate what is
returned, such as shifting bits returned.
Thank-you
 
D

David Wahler

I want to use some old C code such as
#define GEN_STREAMTYPE_NULL 0x51
I need to send this to a server, but it must be declared as a unsigned
four byte constant. I can not just send a string. I love python, but
am looking for information where I can declare this and then send it
through a socket.
Also are there any classes or methods which can manipulate what is
returned, such as shifting bits returned.
Thank-you

See the "struct" module (http://docs.python.org/lib/module-struct.html)
for a couple of really useful functions. For example, you could use:
.... mysocket.send(struct.pack("L", num))
....
As for bit manipulation--it's built in, just like in C.
'0x3400'

Hope this helps.

-- David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top