mirror of
https://github.com/CPunch/LuaPytecode.git
synced 2025-01-22 10:10:06 +00:00
better _get_bits()
This commit is contained in:
parent
3eecd3a8b0
commit
8a1802ad9b
21
luac.py
21
luac.py
@ -115,25 +115,8 @@ instr_lookup_tbl = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
# at [p]osition, with [s]ize of bits
|
# at [p]osition, with [s]ize of bits
|
||||||
def _get_bits(num, p, s):
|
def _get_bits(num: int, p: int, s: int):
|
||||||
# convert number into binary first
|
return (num>>p) & (~((~0)<<s))
|
||||||
binary = bin(num)
|
|
||||||
|
|
||||||
# remove first two characters
|
|
||||||
binary = binary[2:]
|
|
||||||
|
|
||||||
# fill in missing bits
|
|
||||||
for i in range(32 - len(binary)):
|
|
||||||
binary = '0' + binary
|
|
||||||
|
|
||||||
start = len(binary) - (p+s)
|
|
||||||
end = len(binary) - p
|
|
||||||
|
|
||||||
# extract k bit sub-string
|
|
||||||
kBitSubStr = binary[start : end]
|
|
||||||
|
|
||||||
# convert extracted sub-string into decimal again
|
|
||||||
return (int(kBitSubStr,2))
|
|
||||||
|
|
||||||
class LuaUndump:
|
class LuaUndump:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user