annotate python/ppci/bitfun.py @ 354:5477e499b039

Added some sort of string functionality
author Windel Bouwman
date Thu, 13 Mar 2014 18:59:06 +0100
parents 3bb7dcfe5529
children 98ff43cfdd36
rev   line source
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
1
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
2
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
3 def rotate_right(v, n):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
4 """ bit-wise Rotate right n times """
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
5 mask = (2**n) - 1
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
6 mask_bits = v & mask
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
7 return (v >> n) | (mask_bits << (32 - n))
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
8
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
9 def rotate_left(v, n):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
10 assert n >= 0
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
11 assert n < 32
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
12 return rotate_right(v, 32 - n)
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
13
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
14