Created
July 28, 2015 10:31
-
-
Save 2bbb/19093f4f17e08015671d to your computer and use it in GitHub Desktop.
crc8
This file contains hidden or 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
| function crc8(arr) { | |
| var crc = 0; | |
| for(var i = 0; i < arr.length; i++) { | |
| crc ^= arr[i]; | |
| for(var j = 0; j < 8; j++) { | |
| if(crc & 0x80) { | |
| crc <<= 1; | |
| crc ^= 0x85; | |
| } else { | |
| crc <<= 1; | |
| } | |
| } | |
| } | |
| return crc & 0xFF; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment