CRC check, send-side generate check code

Source: Internet
Author: User

/****************************************************************************** * Compilation:javac Crc16ccitt.java * Execution:java Crc16ccitt S * Dependencies: * * Reads in a sequence of bytes and prints out it S-bit * Cylcic redundancy Check (crc-cciit 0xFFFF). * * 1 + x + x^5 + x^12 + x^16 is irreducible polynomial. * *% java Crc16-ccitt 123456789 * Crc16-ccitt = 29b1 * ****************************************************************          /public class Crc16ccitt {public static void main (string[] args) {int CRC = 0xFFFF;   Initial value int polynomial = 0x1021;        0001 0000 0010 0001 (0, 5, N)//byte[] testbytes = "123456789". GetBytes ("ASCII");        byte[] bytes = Args[0].getbytes ();  for (byte b:bytes) {for (int i = 0; i < 8; i++) {Boolean bit = ((b >> (7-i) &                1) = = 1);                Boolean C15 = (CRC >> & 1) = = 1); CRC <<= 1;             if (c15 ^ bit) CRC ^= polynomial;        }} CRC &= 0xFFFF;    System.out.println ("Crc16-ccitt =" + integer.tohexstring (CRC)); }}

The polynomial is 0x1021

CRC check, send-side generate check code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.