idc.py: Implemented rotate_left()

This commit is contained in:
gergely.erdelyi 2008-06-15 12:09:46 +00:00
parent ae694a52ba
commit a979882e50

View File

@ -294,10 +294,29 @@ def rotate_left(value, count, nbits, offset):
@return: the value with the specified field rotated @return: the value with the specified field rotated
all other bits are not modified all other bits are not modified
FIXME: unimplemented
""" """
raise NotImplementedError assert offset >= 0, "offset must be >= 0"
assert nbits > 0, "nbits must be > 0"
mask = 2**(offset+nbits) - 2**offset
tmp = value & mask
if count > 0:
for x in xrange(count):
if (tmp >> (offset+nbits-1)) & 1:
tmp = (tmp << 1) | (1 << offset)
else:
tmp = (tmp << 1)
else:
for x in xrange(-count):
if (tmp >> offset) & 1:
tmp = (tmp >> 1) | (1 << (offset+nbits-1))
else:
tmp = (tmp >> 1)
value = (value-(value&mask)) | (tmp & mask)
return value
def AddHotkey(hotkey, idcfunc): def AddHotkey(hotkey, idcfunc):