Module: Imb::NumericConversions

Included in:
Crc
Defined in:
lib/USPS-intelligent-barcode/numeric_conversions.rb

Overview

Numeric conversions

Internal collapse

Instance Method Details

#numeric_to_bytes(n, min_bytes = 0) ⇒ [Integer]

Convert a numeric to an array of at least min_bytes bytes.

Parameters:

  • n (Numeric)
  • min_bytes (Integer) (defaults to: 0)

Returns:

  • ([Integer])

    Array of bytes



14
15
16
17
18
# File 'lib/USPS-intelligent-barcode/numeric_conversions.rb', line 14

def numeric_to_bytes(n, min_bytes=0)
  n.to_s(16).rjust(2 * min_bytes, '0').scan(/../).map do |s|
    s.to_i(16)
  end
end