本文整理汇总了Python中bitstring.BitArray.int方法的典型用法代码示例。如果您正苦于以下问题:Python BitArray.int方法的具体用法?Python BitArray.int怎么用?Python BitArray.int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitstring.BitArray
的用法示例。
在下文中一共展示了BitArray.int方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: booths
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import int [as 别名]
def booths(m,r):
x=len(bin(m))
y=len(bin(r))
totallength = x+y+1
if m<0 and r<0 or r<0:
bugbit = 1
else:
bugbit = 0
A = BitArray(int = m,length = totallength) << (y+1)
compliment = BitArray(int = -m,length = totallength) << (y+1)
P = BitArray(int = r, length = totallength)
P = P<<1
for i in range(1,y+1):
if P[-2:]=='0b01':
P = BitArray(int = P.int + A.int, length = totallength)
elif P[-2:]=='0b10':
P = BitArray(int = P.int + compliment.int, length = totallength)
P = BitArray(int = P.int>>1, length = totallength)
P = P[:-1]
P.int = P.int + bugbit
steps =""
return '<h1>RESULT</h1><br>'+steps+'<br><h3>decimal value: '+str(P.int)+'</br><br> binary value: '+str(P.bin)+"</h3>"
示例2: booth
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import int [as 别名]
def booth(m,r):
x = len(bin(m))
y = len(bin(r))
#after both numbers are negative, for some reason, the answer is one less than whats expected.
if m < 0 and r < 0 or r < 0 :
bugbit = 1
else:
bugbit = 0
totalLength = x+y + 1
A = BitArray(int = m, length = totalLength) << (y+1)
compliment = BitArray(int = -m, length = totalLength) << (y+1)
P = BitArray(int = r, length = totalLength)
P = P << 1
for i in range(1,y+1):
if P[-2:] == '0b01':
P = BitArray(int = P.int + A.int, length = totalLength)
elif P[-2:] == '0b10':
P = BitArray(int = P.int +compliment.int, length = totalLength)
P = BitArray(int=P.int >> 1,length=totalLength)
P = P[:-1]
P.int = P.int + bugbit
return '<h1>RESULT</h1><br><h3>decimal value: '+str(P.int)+'</br><br> binary value: '+str(P.bin)
示例3: incr_pass
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import int [as 别名]
def incr_pass(board):
new_pass = pass_count(board) + 1
start = 2 * area + 8
a = BitArray('0b00000000')
a.int = new_pass
board[start:start + 8] = a
示例4: incr_turn
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import int [as 别名]
def incr_turn(board):
new_turn = (turn_count(board)) % 2 + 1
start = 2 * area
a = BitArray('0b00000000')
a.int = new_turn
board[start:start + 8] = a