Rat*_*Don 1 python pointers casting
我有一个代码来通过指针将字符串转换为整数.
char s[]="efgh";
int * p;
p=(int *) s;
printf("%d",*p);
Run Code Online (Sandbox Code Playgroud)
这给了我一个输出:
1751606885
Run Code Online (Sandbox Code Playgroud)
这是一个32位整数.
我在python中分析网络数据包,需要在python中使用上述功能.我有一个字符串
s="efgh"
Run Code Online (Sandbox Code Playgroud)
并希望上面的32位整数(从字节级别).
我该怎么做?
小智 8
你可以尝试struct.unpack:
>>> import struct
>>>
>>> struct.unpack('<I', 'efgh')
(1751606885,)
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
359 次 |
| 最近记录: |