Module: Rpremote::Checksum
- Defined in:
- lib/rpremote/checksum.rb,
sig/rpremote.rbs
Class Method Summary collapse
Class Method Details
.crc16(data, initial = 0xFFFF) ⇒ Integer
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rpremote/checksum.rb', line 9 def crc16(data, initial = 0xFFFF) data.each_byte.reduce(initial) do |crc, byte| crc ^= byte << 8 8.times do crc = if crc.nobits?(0x8000) crc << 1 else (crc << 1) ^ 0x1021 end end crc & 0xFFFF end end |
.crc32(data, initial = 0) ⇒ Integer
23 24 25 |
# File 'lib/rpremote/checksum.rb', line 23 def crc32(data, initial = 0) Zlib.crc32(data, initial) end |