如果不清楚关于字节序方面的知识,可以百度下
1.python写法
import socket
def convert_integer():
data = 1234
# 32-bit
print "Original: %s => Long host byte order: %s, Network byte order: %s" %(data, socket.ntohl(data), socket.htonl(data))
# 16-bit
print "Original: %s => Short host byte order: %s, Network byte order: %s" %(data, socket.ntohs(data), socket.htons(data))
if __name__ == '__main__':
convert_integer()
Long host byte order: %s, Network byte order: %s\n", $data, ntohl($data), htonl($data));
printf("Original: %s => Short host byte order: %s, Network byte order: %s\n", $data, ntohs($data), htons($data));
}
convert_integer();
转载请标注文章地址:http://blog.csdn.net/ddjohn/article/details/49931395