Class: Integer
Public Visibility
Public Instance Method Summary
| #bytes(address_length, endian = :little) |
Extracts a sequence of bytes which represent the Integer. Returns: Array |
|---|---|
| #hex_escape |
Returns: String |
| #pack(arch, address_length = arch.address_length) |
Packs the Integer into a String, for a specific architecture and. Returns: String |
Public Instance Method Details
bytes
Extracts a sequence of bytes which represent the Integer.
[View source]
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ronin/formatting/extensions/binary/integer.rb', line 46 def bytes(address_length,endian=:little) endian = endian.to_s buffer = [] if (endian == 'little' || endian == 'net') mask = 0xff address_length.times do |i| buffer << ((self & mask) >> (i*8)) mask <<= 8 end elsif endian == 'big' mask = (0xff << ((address_length-1)*8)) address_length.times do |i| buffer << ((self & mask) >> ((address_length-i-1)*8)) mask >>= 8 end end return buffer end |
hex_escape
[View source]
100 101 102 |
# File 'lib/ronin/formatting/extensions/binary/integer.rb', line 100 def hex_escape "\\x%.2x" % self end |
pack
Packs the Integer into a String, for a specific architecture and address-length.
[View source]
88 89 90 |
# File 'lib/ronin/formatting/extensions/binary/integer.rb', line 88 def pack(arch,address_length=arch.address_length) bytes(address_length,arch.endian).map { |b| b.chr }.join end |