Coder Social home page Coder Social logo

howeyc / crc16 Goto Github PK

View Code? Open in Web Editor NEW
67.0 4.0 19.0 14 KB

Implements the 16-bit cyclic redundancy check, or CRC-16, checksum

Home Page: https://godoc.org/github.com/howeyc/crc16

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%
go crc

crc16's Introduction

GoDoc Build Status

CRC16

A Go package implementing the 16-bit Cyclic Redundancy Check, or CRC-16, checksum.

Usage

To generate the hash of a byte slice, use the crc16.Checksum() function:

import "github.com/howeyc/crc16"

data := byte("test")
checksum := crc16.Checksum(data, crc16.IBMTable)

The package provides the following hashing tables. For each of these tables, a shorthand can be used.

// This is the same as crc16.Checksum(data, crc16.IBMTable)
checksum := crc16.ChecksumIBM(data)

Using the hash.Hash interface also works.

h := crc16.New(crc16.IBMTable)
data := byte("test")
data2 := byte("data")
h.Write(data)
h.Write(data2)
checksum := h.Sum(nil)

Changelog

  • 2017.03.27 - Added MBus checksum
  • 2017.05.27 - Added checksum function without XOR
  • 2017.12.08 - Implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to allow saving and recreating their internal state.

crc16's People

Contributors

howeyc avatar jbriggs-zvelo avatar niondir avatar sibrentalens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

crc16's Issues

crc16 modbus giving wrong result

I tried getting crc for hex string 08000001 using crc16.ChecksumIBM. But instead of 84C3 it is giving me 3226. This is my code:
data := []byte("08000001")
checksum := crc16.ChecksumIBM(data)
fmt.Println("\n checksum:", checksum)

ChecksumCCITT wrong results

Hello,

I just tested the library and got Strange results:
for the "payloads" I have expected values for
[]byte{0x04} -> expected 0x40, 0x84 -> Result B6 5C
[]byte{0x08, 0x00, 0x00, 0x01, 0xF4} -> expected 0x9E, 0x87 -> Result 3D 24

I have double checked my expectations https://www.lammertbies.nl/comm/info/crc-calculation.html

I different crc implemention proofed my results.

Here my sample:

package main

import (
"fmt"

"github.com/howeyc/crc16"

)

func main() {
payload := []byte{0x04}
cs := crc16.ChecksumCCITT(payload)
fmt.Printf("Checksum: %x", cs)

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.