Last active
May 12, 2019 03:43
-
-
Save tjmtmmnk/0bc90e13bc39d7fa819d0cae0dd4db05 to your computer and use it in GitHub Desktop.
crc5を計算してみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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