From a979882e501131a6d2b49b3532b14d537f4c31eb Mon Sep 17 00:00:00 2001 From: "gergely.erdelyi" Date: Sun, 15 Jun 2008 12:09:46 +0000 Subject: [PATCH] idc.py: Implemented rotate_left() --- python/idc.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/python/idc.py b/python/idc.py index 58414bf..7e39b0b 100644 --- a/python/idc.py +++ b/python/idc.py @@ -294,10 +294,29 @@ def rotate_left(value, count, nbits, offset): @return: the value with the specified field rotated 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):