Skip to content

Instantly share code, notes, and snippets.

@tjmtmmnk
Last active May 12, 2019 03:43
Show Gist options
  • Save tjmtmmnk/0bc90e13bc39d7fa819d0cae0dd4db05 to your computer and use it in GitHub Desktop.
Save tjmtmmnk/0bc90e13bc39d7fa819d0cae0dd4db05 to your computer and use it in GitHub Desktop.
crc5を計算してみた
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
uint16_t calc_crc5(uint16_t input) {
uint16_t crc5 = 41; // x^5 + x^3 + 1
uint16_t c = input;
for (int i = 7; i >= 5; --i) //8ビットを計算するときはcrc5では7~5左シフトすればよい
if ((c & (1 << i))) c = (crc5 << (i - 5)) ^ c;
return c;
}
int main(void) {
cout << calc_crc5(148) << endl; //10010100
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment