Code Monkey home page Code Monkey logo

crc32's Introduction

CRC32

Build Status

Description

An Arduino library for calculating a CRC32 checksum.

Features

  • Calculate the CRC32 checksum with minimal memory overhead.
  • Calculate the CRC32 checksum as a stream or using buffered data.
  • Calculate the CRC32 checksum of any arbitrary data type.

Background

A cyclic redundancy check (CRC) is often used to verify data integrity. The CRC32 algorithm is a common way to quickly produce a small, repeatable hash representing an arbitrary block of data. It is often used to verify data packet integrity during serial or network communication.

Use

The CRC32 checksum can be calculated on-the-fly with no buffering or the user can pass a complete data buffer.

Streaming

CRC32 crc;

// Read a stream of bytes.
while (bytesRemain)
{
    // Read a byte from arbitrary source.
    uint8_t byte = readAByteFromAStream();

    // Add the byte to the checksum.
    crc.update(byte);
}

// Calculate the checksum.
uint32_t checksum = crc.finalize();

// To reuse the same instance, call.
crc.reset();

Buffer

uint8_t byteBuffer[32] = { 0x00, 0x01, 0x02, 0x03,
                           0x04, 0x05, 0x06, 0x07,
                           0x08, 0x09, 0x0A, 0x0B,
                           0x0C, 0x0D, 0x0E, 0x0F,
                           0x10, 0x11, 0x12, 0x13,
                           0x14, 0x15, 0x16, 0x17,
                           0x18, 0x19, 0x1A, 0x1B,
                           0x1C, 0x1D, 0x1E, 0x1F };

// Calculate the checksum of an entire buffer at once.
uint32_t checksum = CRC32::calculate(byteBuffer, 32);

Examples

See the included examples and tests for further usage examples.

Compatible Implementations

Changelog

See CHANGELOG.md

License

See LICENSE.md

crc32's People

Contributors

bakercp avatar per1234 avatar vshymanskyy avatar

Watchers

 avatar

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.