diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-07-22 13:05:50 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2017-07-22 13:05:50 +0200 |
commit | 59b898ccee62357cad13f039b68b36acff8c3db2 (patch) | |
tree | 129210840529ca7f99a338f7b38a698494208679 /pyasn1/compat | |
parent | 045ce52349a4494eb6e98d93332811f820ff2fd1 (diff) | |
download | pyasn1-59b898ccee62357cad13f039b68b36acff8c3db2.tar.gz |
fixed compat bin() for negatives
Diffstat (limited to 'pyasn1/compat')
-rw-r--r-- | pyasn1/compat/binary.py | 10 |
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 |