Class: BER::C64
Instance Method Summary collapse
-
#initialize(s) ⇒ C64
constructor
A new instance of C64.
- #to_binary ⇒ Object
- #to_i ⇒ Object
- #to_msgpack ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(s) ⇒ C64
Returns a new instance of C64.
36 37 38 39 40 41 |
# File 'lib/gri/msnmp.rb', line 36 def initialize s @s = s @a = [0, 0, 0, 0, 0, 0, 0, 0] j = 7 (s.size-1).downto(0) {|i| @a[j] = s.getbyte(i); j -= 1} end |
Instance Method Details
#to_binary ⇒ Object
47 48 49 |
# File 'lib/gri/msnmp.rb', line 47 def to_binary @a.pack('C*') end |
#to_i ⇒ Object
55 56 57 58 59 |
# File 'lib/gri/msnmp.rb', line 55 def to_i n = 0 0.upto(7) {|i| n = n * 256 + @a[i]} n end |
#to_msgpack ⇒ Object
51 52 53 |
# File 'lib/gri/msnmp.rb', line 51 def to_msgpack "\xcf" + @a.pack('C*') end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/gri/msnmp.rb', line 43 def to_s '0x' + @a.map {|b| sprintf "%02x", b}.join('') end |