Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6822787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:42:18+00:00 2026-05-26T21:42:18+00:00

I need a CRC check for an application Im writing, but cant figure out

  • 0

I need a CRC check for an application Im writing, but cant figure out for the online code and calculators what im doing wrong. I may just not understand it correctly. This is what I need :

It uses CRC-CCITT with a starting value of 0xFFFF with reverse input bit order. For example, the Get Device Type message is: 0x01, 0x06, 0x01, 0x00, 0x0B, 0xD9. The CRC is 0xD90B.

And this is the code Im using :

public static int CRC16CCITT(byte[] bytes) {
    int crc = 0xFFFF;          // initial value
    int polynomial = 0x1021;   // 0001 0000 0010 0001  (0, 5, 12) 

    for (byte b : bytes) {
        for (int i = 0; i < 8; i++) {
            boolean bit = ((b   >> (7-i) & 1) == 1);
            boolean c15 = ((crc >> 15    & 1) == 1);
            crc <<= 1;
            if (c15 ^ bit) crc ^= polynomial;
         }
    }

    crc &= 0xffff;
    //System.out.println("CRC16-CCITT = " + Integer.toHexString(crc));
    return crc;

Im writing it for an Android device so needs to be in java.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:42:18+00:00Added an answer on May 26, 2026 at 9:42 pm

    Here is the code that I use in my App (It works).

    static public int GenerateChecksumCRC16(int bytes[]) {
    
            int crc = 0xFFFF;
            int temp;
            int crc_byte;
    
            for (int byte_index = 0; byte_index < bytes.length; byte_index++) {
    
                crc_byte = bytes[byte_index];
    
                for (int bit_index = 0; bit_index < 8; bit_index++) {
    
                    temp = ((crc >> 15)) ^ ((crc_byte >> 7));
    
                    crc <<= 1;
                    crc &= 0xFFFF;
    
                    if (temp > 0) {
                        crc ^= 0x1021;
                        crc &= 0xFFFF;
                    }
    
                    crc_byte <<=1;
                    crc_byte &= 0xFF;
    
                }
            }
    
            return crc;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a need to provide a 32-bit CRC (Cyclic Redundancy Check) of all
In my code i need to calculate CRC-16 16 bit values for the HEX
Need some regular expressions help. So far I have my code working to allow
I need a CRC mechanism to calculate the CRC of a number of strings,
Need to add it to textview, for example, standard java-code.
Need some insight on how this works I have the following piece of code
First off; I am not necessarily looking for Delphi code, spit it out any
I have a CRC class written in VB.NET. I need it in C#. I
I Need Convert This Code To .net (C# or VB.net) Please Help Me For
I've inherited a Delphi application which I need to convert to a C# application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.