Class: Imb::Crc

Inherits:
Object
  • Object
show all
Includes:
NumericConversions
Defined in:
lib/USPS-intelligent-barcode/crc.rb

Overview

Calculates the Intelligent Mail Barcode CRC.

Internal collapse

Methods included from NumericConversions

#numeric_to_bytes

Instance Method Details

#crc(binary_data) ⇒ Integer

Calculate a CRC.

Parameters:

  • binary_data (Integer)

    A 102-bit integer

Returns:

  • (Integer)

    An 11-bit CRC



17
18
19
20
21
22
23
24
25
# File 'lib/USPS-intelligent-barcode/crc.rb', line 17

def crc(binary_data)
  crc = MASK
  bytes = numeric_to_bytes(binary_data, NUM_INPUT_BYTES)
  crc = crc_byte(crc, bytes.first, LEADING_BITS_TO_IGNORE)
  for byte in bytes[1...NUM_INPUT_BYTES]
    crc = crc_byte(crc, byte, 0)
  end
  crc
end