Class: Codec::Numbin
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
#add_sub_codec, #decode, #decode_with_length, #encode_with_length, #eval_length, #get_length, #get_sub_codecs, #initialize
Constructor Details
This class inherits a constructor from Codec::Base
Class Method Details
.numbin(number, maxlength) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/codec/fix.rb', line 21 def self.numbin(number,maxlength) out = "" while number > 0 out << (number % 256).chr number /= 256 end # handle length if defined if maxlength > 0 while out.length < maxlength out << 0.chr end out = out[0,maxlength] end out = 0.chr if out == "" return out.reverse end |