473,322 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Hex checksum

Hey all,
I'm completely new to programming of any kind and I decided to try and write a driver for a XM tuner.
I'm trying to figure out how to send a hex array which has 4 bytes that will change with each command. The 4 bytes will be tuner number (appears twice), the actual event wanting to happen, and the checksum.
To start I want to just figure out how to calculate the checksum and take it from there.
This is the formula:
Step 1: Add byte values: 0xF0 + 0x00 + 0x67 + 0x7C + 0xF1 + 0x0F = 0x2D3
Step 2: Add byte count: 0x2D3 + 6 (Decimal value byte count) = 0x2D9
Step 3: Bitwise AND with 0x7F: 0x02D9 & 0x007F = 0x59 for the Checksum

Any ideas?
Thanks
Jan 30 '10 #1
5 11596
RedSon
5,000 Expert 4TB
Hey check this out to see if it will help you:

http://en.wikipedia.org/wiki/Bitwise_operation
Jan 30 '10 #2
Anyone else have any ideas, or preferably, some examples?
Jan 31 '10 #3
You posted question in C# thread.
Here is C# implementation of your three steps.
Expand|Select|Wrap|Line Numbers
  1.             byte[] byteArray = { 0xF0, 0x00, 0x67, 0x7C, 0xF1, 0x0F };
  2.  
  3.             //Variable with result of your calculation.
  4.             int result = 0;
  5.  
  6.             //Step1: Add byte values.            
  7.             foreach (byte value in byteArray) {
  8.                 result += value;
  9.             }
  10.  
  11.             //Step2: Add byte count.
  12.             result += 6;
  13.  
  14.             //Step3: Bitwise AND with 0x7F.
  15.             result &= 0x7F;
Jan 31 '10 #4
Almost...
It's just not returning the correct checksum.

If you try this:

Expand|Select|Wrap|Line Numbers
  1. byte[] byteArray = { 0xF0, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x70, 0x05, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x3B, 0x00, 0x70, 0x00, 0x00, 0x00, 0x01 };
And change the byte count to 21, it should return 29 but it returns 41?
Feb 1 '10 #5
Decimal 41 is hex 29. Console.WriteLine print all numbers as decimal
Feb 1 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Mercuro | last post by:
Hello i'm looking for a simple way to checksum my data. The data is 70 bytes long per record, so a 32 byte hex md5sum would increase the size of my mysql db a lot. I'm looking for something...
2
by: pradeep | last post by:
I have 2 data files, DATA1 and DATA2 , both same. My task is to: Open DATA1, compute the checksum and put it in the end of the file(don't bother about boundary conditions).close DATA1 Open...
4
by: Abby | last post by:
I have an array which contain Hex no. in each position. For examples, unsigned char data; data = 0x00; data = 0x01; data = 0x02; data = 0xE; data = 0xEF; --> This is the checksum value
2
by: Abby | last post by:
I need to do 8 bits 2's complement checksum, so I wrote code in order to see if the checksum calculation is correct. ===========================================================================...
6
by: Kevin | last post by:
I'm on Sun 0S 5.8 and need to calculate the checksum of certain sections in an ELF binary file. Specifically .text to .rodata. I'm able to parse through to the program header table and then find...
6
by: Astroman | last post by:
Hi guys and girls. This is my first time posting here so go easy :) . I was wondering if someone could please interpret how this csum() function works in the following C code. I know that the...
3
by: Andrus | last post by:
Device connected to serial port accepts data packets in the form 02 0x57 ll ll 00 00 00 00 dd..dd cc cc 02 (1 byte ) is message prefix 0x57 (1 byte) is message type (W=Write) ll ll ( 2 bytes)...
1
by: Terry | last post by:
I'm trying to calculate the checksum for UDP packet. The algorithm itself is not difficult (lots of examples out there), but what I'm having the most trouble with is determining the byte order...
1
by: gameMaker | last post by:
I need to be able to build my code into a dll where the checksum of the dll is the same everytime I build it. In other words, the same exact code gives me a different checksum each time I build...
4
by: Rain | last post by:
hi, need help here, does anyone know how to use or does any one have the code for checksum? I want to checksum a string to be sent using udp and checksum it again when received.. does anyone...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.