#!/usr/bin/env python # coding: utf-8 # In[10]: from __future__ import print_function, division import struct # In[13]: num = -3333 raw = [(num & 0xff00)>>8, (num & 0xff)] # hi, lo print('raw', raw) print('raw byte 0:', raw[0]) print('raw byte 1:', raw[1]) data = bytearray(raw) print('big endian:', data) # In[12]: ans = struct.unpack('>h', data)[0] # returns a tuple print(ans) # In[16]: b = bytearray([23,123,55,234]) ans = struct.unpack('>hh', b) print(ans) # In[ ]: ()