是否有蟒蛇一个快速的方法来分割32位的变量,比如a1a2a3a4
到a1
,a2
,a3
,a4
快?我已经通过将值更改为十六进制然后拆分它来完成它,但似乎浪费时间做int
- > string
- > int
.
我尝试的一切都给了我错误的输出值.我甚至复制了C代码并更改了它们,以便它们可以在python中工作,我仍然得到错误的输出.怎么了?
import os, math
def makehex(value,size=8):
value = hex(value)[2:]
if value[-1] == 'L':
value = value[0:-1]
while len(value)<size:
value = '0' + value
return value
def makebin(value,size=32):
value = bin(value)[2:]
while len(value)<size:
value = '0' + value
return value
def ROL(value,n):
return (value << n) | (value >> 32-n)
def little_end(string,base = 16):
t = ''
if base == 2:
s= 8
if base == 16:
s = 2
for x in range(len(string)/s):
t = string[s*x:s*(x+1)] + t
return t …
Run Code Online (Sandbox Code Playgroud)