You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.3 KiB
Go

9 years ago
package dmr
9 years ago
// G(x) = x^9+x^6+x^4+x^3+1
9 years ago
func crc9(crc *uint16, b uint8, bits int) {
var v uint8 = 0x80
for i := 0; i < 8-bits; i++ {
v >>= 1
}
for i := 0; i < 8; i++ {
xor := (*crc)&0x0100 > 0
(*crc) <<= 1
// Limit the number of shift registers to 9.
*crc &= 0x01ff
if b&v > 0 {
(*crc)++
}
if xor {
9 years ago
(*crc) ^= 0x0059
9 years ago
}
v >>= 1
}
}
func crc9end(crc *uint16, bits int) {
for i := 0; i < bits; i++ {
xor := (*crc)&0x100 > 0
(*crc) <<= 1
// Limit the number of shift registers to 9.
*crc &= 0x01ff
if xor {
9 years ago
(*crc) ^= 0x0059
9 years ago
}
}
}
9 years ago
// G(x) = x^16+x^12+x^5+1
9 years ago
func crc16(crc *uint16, b byte) {
var v uint8 = 0x80
for i := 0; i < 8; i++ {
9 years ago
xor := ((*crc) & 0x8000) != 0
9 years ago
(*crc) <<= 1
if b&v > 0 {
(*crc)++
}
if xor {
9 years ago
(*crc) ^= 0x1021
9 years ago
}
v >>= 1
}
}
func crc16end(crc *uint16) {
for i := 0; i < 16; i++ {
9 years ago
xor := ((*crc) & 0x8000) != 0
9 years ago
(*crc) <<= 1
if xor {
9 years ago
(*crc) ^= 0x1021
9 years ago
}
}
}
func crc32(crc *uint32, b byte) {
var v uint8 = 0x80
for i := 0; i < 8; i++ {
xor := ((*crc) & 0x80000000) > 0
(*crc) <<= 1
if b&v > 0 {
(*crc)++
}
if xor {
9 years ago
(*crc) ^= 0x04c11db7
9 years ago
}
v >>= 1
}
}
func crc32end(crc *uint32) {
for i := 0; i < 32; i++ {
xor := ((*crc) & 0x80000000) > 0
(*crc) <<= 1
if xor {
9 years ago
(*crc) ^= 0x04c11db7
9 years ago
}
}
}