我很新的十六进制一般,我有一个应用程序,需要我分裂一个十六进制数字。例如,给定数字0x607F,我需要返回高(0x60)或低(0x7F)字节。在python中分割十六进制的最佳方法是什么?
这是可能的实施,但它感觉有点不可思议。有没有更多的标准方式来做到这一点在Python中?
def byte(integer,highlow):
assert highlow=='high' or highlow=='low'
if highlow=='high':
return hex(int(bin(integer)[:-8],2))
if highlow=='low':
return hex(int(bin(integer)[-8:],2))
刚刚在我的机器上发现了unutbu的答案...... 1.8us vs 2.22us。 FWIW我的代码是在4.97us进来,只计算一个。 – Chris 2013-02-23 03:26:15