class Digest::CRC16

Implements the CRC16 algorithm.

Constants

INIT_CRC
TABLE

Generated by `./pycrc.py –algorithm=table-driven –model=crc-16`

WIDTH

Public Class Methods

pack(crc) click to toggle source

Packs the CRC16 checksum.

@param [Integer] crc

The CRC16 checksum to pack.

@return [String]

The packed CRC16 checksum.
# File lib/digest/crc16.rb, line 58
def self.pack(crc)
  buffer = ''

  buffer << ((crc & 0xff00) >> 8).chr
  buffer << (crc & 0xff).chr

  buffer
end

Public Instance Methods

update(data) click to toggle source

Updates the CRC16 checksum.

@param [String] data

The data to update the checksum with.
# File lib/digest/crc16.rb, line 73
def update(data)
  data.each_byte do |b|
    @crc = ((@table[(@crc ^ b) & 0xff] ^ (@crc >> 8)) & 0xffff)
  end

  return self
end