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 8919017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:54:28+00:00 2026-06-15T05:54:28+00:00

I have to create a CRC16 checksum for a firmware update. When I send

  • 0

I have to create a CRC16 checksum for a firmware update. When I send this Data (converted from hex-string to byte[])

020000810000120000000002F001128100000C9462050C9481050C9481050C9481050C9481050C9481050C9481050C9481050C9481050C9481050C9481050C94

I get following CRC16 from the controller

-17514

now I try to check this in Java, but I can’t get the same value.

This are the original functions in C:

static uint16_t crc16_update(uint16_t crc, uint8_t a)
{
  crc ^= a;
  for (unsigned i = 0; i < 8; ++i) {
    if (crc & 1)
      crc = (crc >> 1) ^ 0xA001;
    else
      crc = (crc >> 1);
  }
  return crc;
}


static uint16_t crc16(const uint8_t *b, size_t l)
{
  uint16_t crc = 0;
  while (l-- > 0)
    crc = crc16_update(crc, *b++);
  return crc;
}

this are my converted functions in java:

public static int crc16_update(int crc, int a) {
    crc ^= a;
    for (int i = 0; i < 8; ++i) {
        if ((crc & 1) != 0) {
            crc = (crc >> 1) ^ 0xA001;
        } else {
            crc = (crc << 1);
        }
    }
    return crc;
}

public static int crc16(byte[] bytes) {
    int crc = 0;
    for (byte b:bytes) {
        crc = crc16_update(crc, b);
    }
    return crc;
}

… but it doesn’t work. What’s wrong with it?

  • 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-06-15T05:54:30+00:00Added an answer on June 15, 2026 at 5:54 am

    I’ve found the right way. Now it work’s! I think the problem was the intern converting between short and int.

    public static int crc16_update(int crc, byte a) {
        crc ^= ((a+128) & 0xff);
        for (int i = 0; i < 8; ++i) {
            if ((crc & 1) != 0) {
                crc = ((crc >>> 1) ^ 0xA001) & 0xffff;
            }
            else {
                crc = (crc >>> 1) & 0xffff;
            }
        }
        return crc;
    }
    
    public static short crc16(byte[] bytes) {
        int crc = 0;
        for (byte b : bytes) {
            crc = crc16_update(crc, b);
        }
        return (short) crc;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create a script that I like to send some data to another
I have create a simple grid that retrieves data from a server through php.
I have create program to send mail with my some detail from sqlite database
I have create a vcf file that contains contacts by using this code ContentResolver
I have create my own NSOpenGLView class, right now the data that i want
I have create name range on sheet A so I need to use this
I have create in MySQdb a DB with a table named example,in this table
I have create the class HoverButton which derives from Form.Button. Here I override the
I have create a function which to send mail. Its works when I invoke
I have create new page with my custom template. This page will be used

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.