#!/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]