__MagicPower
Do one thing and do it best!

导航

 
#!/usr/bin/env python

import socket

def convert_integer():
	data = 1234
	#32bit
	print "Original:%s =>Long host byte order:%s, Network byte order:\
	order:%s"%(data,socket.ntohl(data),socket.htonl(data))
	#16bit
	print "Original:%s =>Long host byte order:%s, Network byte order:\
	order:%s"%(data,socket.ntohs(data),socket.htons(data))

if __name__ == '__main__':
	convert_integer()

TEST:

Original:1234 =>Long host byte order:3523477504, Network byte order: order:3523477504
Original:1234 =>Long host byte order:53764, Network byte order: order:53764
[Finished in 0.1s]

posted on 2015-12-21 15:52  __MagicPower  阅读(184)  评论(0编辑  收藏  举报