Class: Digest::CRC16QT
- Inherits:
-
CRC16CCITT
- Object
- Class
- CRC
- CRC16
- CRC16CCITT
- Digest::CRC16QT
- Defined in:
- lib/digest/crc16_qt.rb
Overview
Implements the CRC16_CCITT algorithm used in QT algorithms.
Constant Summary collapse
- FINAL_XOR =
0xffff
- REVERSE_CRC_RESULT =
true
- REVERSE_DATA =
true
Constants inherited from CRC16CCITT
Digest::CRC16CCITT::INIT_CRC, Digest::CRC16CCITT::TABLE
Constants inherited from CRC16
Digest::CRC16::INIT_CRC, Digest::CRC16::TABLE, Digest::CRC16::WIDTH
Constants inherited from CRC
Digest::CRC::INIT_CRC, Digest::CRC::TABLE, Digest::CRC::WIDTH, Digest::CRC::XOR_MASK
Instance Method Summary collapse
- #checksum ⇒ Object
- #revert_bits(cc) ⇒ Object protected
- #revert_byte(cc) ⇒ Object protected
-
#update(data) ⇒ Object
Updates the CRC16 checksum.
Methods inherited from CRC16
Methods inherited from CRC
#<<, #block_length, checksum, #digest_length, #finish, #initialize, pack, #reset
Constructor Details
This class inherits a constructor from Digest::CRC
Instance Method Details
#checksum ⇒ Object
31 32 33 34 35 36 |
# File 'lib/digest/crc16_qt.rb', line 31 def checksum crc = @crc + 0 crc ^= FINAL_XOR if FINAL_XOR crc = revert_bits crc if REVERSE_CRC_RESULT return crc end |
#revert_bits(cc) ⇒ Object (protected)
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/digest/crc16_qt.rb', line 40 def revert_bits(cc) ob = 0 b = (1 << 15) 16.times do |t| ob |= (1 << t) if (cc & b) != 0 b >>= 1 end return ob end |
#revert_byte(cc) ⇒ Object (protected)
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/digest/crc16_qt.rb', line 52 def revert_byte(cc) ob = 0 b = (1 << 7) 8.times do |t| ob |= (1 << t) if (cc & b) != 0 b >>= 1 end return ob end |
#update(data) ⇒ Object
Updates the CRC16 checksum.
22 23 24 25 26 27 28 29 |
# File 'lib/digest/crc16_qt.rb', line 22 def update(data) data.each_byte do |b| b = revert_byte(b) if REVERSE_DATA @crc = ((@table[((@crc >> 8) ^ b) & 0xff] ^ (@crc << 8)) & 0xffff) end return self end |