forked from natural/java2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbsr.py
More file actions
26 lines (24 loc) · 830 Bytes
/
bsr.py
File metadata and controls
26 lines (24 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def bsr(value, bits):
""" bsr(value, bits) -> value shifted right by bits
This function is here because an expression in the original java
source contained the token '>>>' and/or '>>>=' (bit shift right
and/or bit shift right assign). In place of these, the python
source code below contains calls to this function.
Copyright 2003 Jeffrey Clement. See pyrijnadel.py for license and
original source.
"""
minint = -2147483648
if bits == 0:
return value
elif bits == 31:
if value & minint:
return 1
else:
return 0
elif bits < 0 or bits > 31:
raise ValueError('bad shift count')
tmp = (value & 0x7FFFFFFE) // 2**bits
if (value & minint):
return (tmp | (0x40000000 // 2**(bits-1)))
else:
return tmp