Mercurial > lcfOS
comparison python/ppci/bitfun.py @ 347:742588fb8cd6 devel
Merge into devel branch
author | Windel Bouwman |
---|---|
date | Fri, 07 Mar 2014 17:10:21 +0100 |
parents | 3bb7dcfe5529 |
children | 98ff43cfdd36 |
comparison
equal
deleted
inserted
replaced
343:11c5a8a70c02 | 347:742588fb8cd6 |
---|---|
1 | |
2 | |
3 def rotate_right(v, n): | |
4 """ bit-wise Rotate right n times """ | |
5 mask = (2**n) - 1 | |
6 mask_bits = v & mask | |
7 return (v >> n) | (mask_bits << (32 - n)) | |
8 | |
9 def rotate_left(v, n): | |
10 assert n >= 0 | |
11 assert n < 32 | |
12 return rotate_right(v, 32 - n) | |
13 | |
14 |