Python实现64位整型主机字节顺序和网络字节顺序的转换
时间:2010-06-24 来源:zhcn381
使用struct,相当轻松
import struct
def htonll(Val): strNative = struct.pack('Q', Val) BEVal = struct.unpack('!Q', strNative)[0] return BEVal
def ntohll(Val): strBE = struct.pack('!Q', Val) NativeVal = struct.unpack('Q', strBE)[0] return NativeVal
import struct
def htonll(Val): strNative = struct.pack('Q', Val) BEVal = struct.unpack('!Q', strNative)[0] return BEVal
def ntohll(Val): strBE = struct.pack('!Q', Val) NativeVal = struct.unpack('Q', strBE)[0] return NativeVal
相关阅读 更多 +