title: ASN.1 real number encoding in base 2 with pyasn1
body: <p>I started to learn ASN.1 and used pyasn1 for my experiments.
  By default pyasn1 use base 10 to encode real numbers.
  It is also support base 2 and I need to use base 2 in my program.
  But it looks something wrong with encoding.
  I found strange behaviour when encode numbers 0.5 and 1.0 in base 2.
  The test code is:</p>
  
  <pre><code>from pyasn1.type import univ
  from pyasn1.codec.ber import encoder, decoder
  import binascii
  
  for i in xrange(4):
      r=univ.Real((1,2,-i))
      m=encoder.encode(r)
      print r,"-&gt;",decoder.decode(m)[0],"data:",binascii.b2a_hex(m)
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>1.0 -&gt; 2.0 data: 0903830101
  0.5 -&gt; 2.0 data: 0903830101
  0.25 -&gt; 0.25 data: 090380fe01
  0.125 -&gt; 0.125 data: 090380fd01
  </code></pre>
  
  <p>Both numbers 0.5 and 1.0 encoded as the same sequence and decoded as 2.0 number.
  The same behaviour is in both BER and DER encoders.</p>
  
  <p>Could you please help me to find out what is wrong?</p>