python–ntohll和htonll的实现(转载)
来源:互联网 发布:安全生产网络知识竞赛 编辑:程序博客网 时间:2024/05/30 05:28
可以利用python中的struct包中的如下东东进行转换:
1、字节序:
Character Byte order Size and alignment @nativenative=nativestandard<little-endianstandard>big-endianstandard!network (= big-endian)standard
2、字节数
Format C Type Python Notes xpad byteno value ccharbytes of length 1 bsigned charinteger(1)Bunsigned charinteger ?_Boolbool(2)hshortinteger Hunsigned shortinteger iintinteger Iunsigned intinteger llonginteger Lunsigned longinteger qlong longinteger(3)Qunsigned long longinteger(3)ffloatfloat ddoublefloat schar[]bytes(1)pchar[]bytes(1)Pvoid *integer
3、自定义函数
1、字节序:
2、字节数
3、自定义函数
使用struct,相当轻松
import struct
htonll = lambda a:struct.unpack('!Q', struct.pack('Q', a) )[0]
htonll = lambda a:struct.unpack('!Q', struct.pack('Q', a) )[0]
ntohll = lambda a:struct.unpack('Q', struct.pack('!Q', a))[0]
0 0
- python–ntohll和htonll的实现(转载)
- 实现一个ntohll
- 转载!!!决策树的python实现
- 【转载】跳表SkipList的原理和实现
- 实现复数和实数之间的转载
- 【转载】Comparable接口的实现和使用
- [转载]Python实现ASP+ACCESS注入的工具源代码
- [转载]python中package机制的两种实现方式
- 在Python中实现你自己的推荐系统【转载】
- [转载]事件驱动的简明讲解(python实现)
- 【转载】python的GUI实现模块之Tkinter 编程入门
- Python的历史(转载)
- 转载的python简史
- python单引号、双引号和三双引号的区别(转载)
- Python String和PyQt QString的区别(转载)
- 转载的:Python os 和 os.path模块详解
- 转载——python和爬虫的正则表达式
- Windows下python和pip的环境配置 ---转载
- [cocos2dx]cocos2dx-lua中class语法
- 黑马程序员——c语言基础:scanf函数
- python - 动态加载模块和类
- CSU 1612: Destroy Tunnels 强连通分量 Kosaraju算法
- imageNamed 与 imageWithContentsOfFile的区别
- python–ntohll和htonll的实现(转载)
- Cocos2d-x 3.6 vs2012 更新设置
- scala xml系列化
- SQLServer---查询过程中的数据类型转化
- fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- 188 Best Time to Buy and Sell Stock IV
- iOS中将汉字转换成拼音
- Solr5 快速开始
- sgu214:Weird Dissimilarity(DP)