aboutsummaryrefslogtreecommitdiff
path: root/pyasn1/compat
diff options
context:
space:
mode:
Diffstat (limited to 'pyasn1/compat')
-rw-r--r--pyasn1/compat/binary.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/pyasn1/compat/binary.py b/pyasn1/compat/binary.py
index 65c42c7..86f6e5d 100644
--- a/pyasn1/compat/binary.py
+++ b/pyasn1/compat/binary.py
@@ -10,6 +10,14 @@ if version_info[0:2] < (2, 6):
def bin(value):
bitstring = []
+ if value > 0:
+ prefix = '0b'
+ elif value < 0:
+ prefix = '-0b'
+ value = abs(value)
+ else:
+ prefix = '0b0'
+
while value:
if value & 1 == 1:
bitstring.append('1')
@@ -20,6 +28,6 @@ if version_info[0:2] < (2, 6):
bitstring.reverse()
- return '0b' + ''.join(bitstring)
+ return prefix + ''.join(bitstring)
else:
bin = bin