You can try struct.unpack
:
>>> import struct
>>>
>>> struct.unpack('<I', 'efgh')
(1751606885,)
>>>
Domanda
I've a c code to type cast a string to an integer via pointer.
char s[]="efgh";
int * p;
p=(int *) s;
printf("%d",*p);
This gives me an output of:
1751606885
Which is a 32 bit integer.
I'm analyzing a network packet in python and need the above functionality in python. I've a string
s="efgh"
and want the above in a 32 bit integer (from the byte level).
How can I do it?
Soluzione
You can try struct.unpack
:
>>> import struct
>>>
>>> struct.unpack('<I', 'efgh')
(1751606885,)
>>>