Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package crc4
- func Checksum(b []byte) uint8 {
- crc := 0xFFFF
- for bI := 0; bI < len(b); bI++ {
- bit := uint8(0x80)
- for bitI := 0; bitI < 8; bitI++ {
- xorFlag := ((crc & 0x8000) == 0x8000)
- crc = crc << 1
- if ((b[bI] & bit) ^ uint8(0xFF)) != uint8(0xFF) {
- crc = crc + 1
- }
- if xorFlag {
- crc = crc ^ 0x1021
- }
- bit = bit >> 1
- }
- }
- return uint8(crc)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement