fixed the implementation of Bignum#to_ber.
This commit is contained in:
parent
0bf35f8d3e
commit
5f197cc040
3 changed files with 39 additions and 4 deletions
|
@ -409,9 +409,22 @@ end # class Fixnum
|
|||
class Bignum
|
||||
|
||||
def to_ber
|
||||
i = [self].pack('w')
|
||||
i.length > 126 and raise Net::BER::BerError.new( "range error in bignum" )
|
||||
[2, i.length].pack("CC") + i
|
||||
#i = [self].pack('w')
|
||||
#i.length > 126 and raise Net::BER::BerError.new( "range error in bignum" )
|
||||
#[2, i.length].pack("CC") + i
|
||||
|
||||
# Ruby represents Bignums as two's-complement numbers so we may actually be
|
||||
# good as far as representing negatives goes.
|
||||
# I'm sure this implementation can be improved performance-wise if necessary.
|
||||
sz = self.size
|
||||
out = "\000" * sz
|
||||
(sz*8).times {|bit|
|
||||
if self[bit] == 1
|
||||
out[bit/8] += (1 << (bit % 8))
|
||||
end
|
||||
}
|
||||
|
||||
[2, sz].pack("CC") + out.reverse
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue