crc16.hpp 285 B

12345678910111213141516171819
  1. #pragma once
  2. //CRC-16/KERMIT
  3. namespace nall::CD {
  4. inline auto CRC16(array_view<uint8_t> data) -> uint16_t {
  5. uint16_t crc = 0;
  6. while(data) {
  7. crc ^= *data++ << 8;
  8. for(uint bit : range(8)) {
  9. crc = crc << 1 ^ (crc & 0x8000 ? 0x1021 : 0);
  10. }
  11. }
  12. return ~crc;
  13. }
  14. }