Skip to content
Snippets Groups Projects
Commit 2e4c7ef0 authored by Pierre LALET's avatar Pierre LALET
Browse files

Implement a binrepr() function working with both Python 2.5 and 2.6+

parent a814731c
No related branches found
No related tags found
No related merge requests found
...@@ -426,6 +426,22 @@ def incremental_label(label="tag%05i", start=0): ...@@ -426,6 +426,22 @@ def incremental_label(label="tag%05i", start=0):
yield label % start yield label % start
start += 1 start += 1
# Python <= 2.5 do not provide bin() built-in function
try:
bin(0)
except NameError:
def _binrepr(val):
while val:
yield val & 1
val >>= 1
binrepr = lambda val: "".join(reversed([str(bit) for bit in
_binrepr(val)])) or "0"
else:
binrepr = lambda val: bin(val)[2:]
######################### #########################
#### Enum management #### #### Enum management ####
######################### #########################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment