473,388 Members | 1,322 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,388 software developers and data experts.

Calculate Checksum VB 6

Could I have some help calculating a checksum for receive data from a Video server?

The data is in Hex and the values and here is an example:
20 24 49 4C 30 31 37 38 37 39 CS
CS=Checksum

the cheksum is the 2's complement of the sum of the values.

If anyone have an algoritm or knows how to do it, please help me, thanks
Jan 15 '07 #1
3 9225
Killer42
8,435 Expert 8TB
Could I have some help calculating a checksum for receive data from a Video server?

The data is in Hex and the values and here is an example:
20 24 49 4C 30 31 37 38 37 39 CS
CS=Checksum

the cheksum is the 2's complement of the sum of the values.

If anyone have an algoritm or knows how to do it, please help me, thanks
The algorithm would be simple enough. Convert each three bytes (two if you inserted the spaces for readability) into a number, add them up, calculate the two's complement, and see whether it matches.
Expand|Select|Wrap|Line Numbers
  1. Dim sLine As String, I As Long
  2. Dim lValue As Long, lSum As Long, lChecksum As Long
  3. sLine = "20 24 49 4C 30 31 37 38 37 39 CS"
  4. For I = 0 To 9
  5.   lValue = Val( "&h" & Mid$(sLine, I * 43) )
  6.   lSum = lSum + lValue
  7. Next
  8. lChecksum = val( "&h" & Right$(sLine, 2) )
  9.  
You now have the sum and the checksum. Do the two's complement thing (obviously I haven't read up on how, yet) and see whether they match.
Jan 16 '07 #2
Killer42
8,435 Expert 8TB
Once you have each byte value, you could call this routine to calculate the two's complement...
Expand|Select|Wrap|Line Numbers
  1. Public Function TwosComplement(ByVal src As Long) As Byte
  2.   Dim Bit As Long, Result As Long, Power As Long, Value As Long
  3.   For Power = 7 To 0 Step -1
  4.     Value = 2 ^ Power
  5.     Bit = src \ Value
  6.     src = src - Bit * Value
  7.     Bit = Abs(Bit - 1)
  8.     Result = Result + Bit * Value
  9.   Next
  10.   TwosComplement = Result
  11. End Function
However, once I saw the results I realised you can simplify this just a tiny bit...
Expand|Select|Wrap|Line Numbers
  1. TwosComplement = 255 - ByteValue
:D

You should now have all the necessary parts to do the job.
Jan 16 '07 #3
thanks killer i'll try with that...thanks for your time
Jan 16 '07 #4

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

Similar topics

7
by: sea | last post by:
I understand that it is possible to test the integrity of data using something called checksum? What exactly is this and how do I use it in DB2? I've searched a lot of places but could not find an...
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
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...
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...
34
by: Zahid Faizal | last post by:
Kindly suggest a good opensource package (in C or C++) that can compute the checksum of a file. SHA2 would be preferable, but SHA1/SHA0/MD5 would be acceptable as well. We have cards with...
15
by: rjfjohnson | last post by:
Hey, I am trying to communicate with serial device and I need to know the method used to calculate the 1digit checksum. I have a commercial program that can communicate with the device, and a...
5
by: =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?= | last post by:
Hi, how can I calculate the checksum (CRC-16) from the byte I retrieve from a hardware device through the RS232 serial port? Christian
1
by: Imran | last post by:
Hello all I am trying to calculate a checksum correction for 16 byte checksum calculation. I have 1 lines of data xxxxxxxxyyyyyyyy80804C0400004204UUUUUUUU What I am trying to achive is...
3
by: Adriano | last post by:
Hello. I have a situation where need to calculate a checksum of some byte array. Here's the sample output from server: 2008-09-30 11:35:00 `SC`00541.00TJ123456PPC 00000000DLGLGN...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.