import ctypes num32 = ctypes.c_long() num32 = 0x12345678 b_array = num32.to_bytes(4,'big') i16u = (b_array[0]<<8) + b_array[1] i16l = (b_array[2]<<8) + b_array[3] print("Two 16bit numbers are 0x{0:02x} and 0x{1:02x}".format(i16u,i16l))