-
Weird Checksum
Greetings,
I need to calc a checksum for a block of 16 data points represented as hex
values. Each block of data starts with 21 00 and ends with 03. Each data
point is a 16 bit value with a range of 00 00 - 7f ff (0 - 32,767)
The checksum can not exceed ff. I have tried several crc calcs with no luck.
Any ideas?
I have included a few examples.
STX = [21][00]
Data points 1 - 8
[00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]
Data points 9 - 16
[00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]
EOT = [03]
ChkSum = [22]
[21][00]
[00][00][7f][ff][00][00][00][00][00][00][00][00][00][00][00][00]
[00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]
[03]
[a2]
[21][00]
[00][00][7f][ff][7f][ff][00][00][00][00][00][00][00][00][00][00]
[00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]
[03]
[22]
[21][00]
[00][00][7f][ff][00][64][00][00][00][00][00][00][00][00][00][00]
[00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]
[03]
[c6]
[21][00]
[00][00][7f][ff][00][66][00][00][00][00][00][00][00][00][00][00]
[00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]
[03]
[c4]
Thanks for any help.
Ken
-
Re: Weird Checksum
On 20 Jul 2000 18:22:25 -0700, "Ken R." <Krac@acommsw.com> wrote:
»I need to calc a checksum for a block of 16 data points represented as hex
»values. Each block of data starts with 21 00 and ends with 03. Each data
»point is a 16 bit value with a range of 00 00 - 7f ff (0 - 32,767)
»The checksum can not exceed ff. I have tried several crc calcs with no luck.
»Any ideas?
(snip)
From your examples, it looks like the checksum is obtained by
simply XOR-ing all 35 bytes of a block together.
--
Paul Marshall
pmarshal@vulcraft-al.com
-
Re: Weird Checksum
Hi Paul,
>From your examples, it looks like the checksum is obtained by
>simply XOR-ing all 35 bytes of a block together.
I tried the XOR but the result needs to be a value between 00 and ff. I tried
a mod 255 on the result. The closest I got has taking the 2 right side characters
from the Hex result.
Ken
-
Re: Weird Checksum
On 24 Jul 2000 17:07:43 -0700, "Ken R." <krac@acommsw.com> wrote:
»>From your examples, it looks like the checksum is obtained by
»>simply XOR-ing all 35 bytes of a block together.
»
»
»I tried the XOR but the result needs to be a value between 00 and ff. I tried
»a mod 255 on the result. The closest I got has taking the 2 right side characters
»from the Hex result.
Hi Ken,
A byte is in the range [00, FF]. XOR-ing two bytes together
results in one byte, still in the range [00, FF]. You should
never get a result over 255 (= FF).
Try this:
==========
Public Function XORByteArray(bt() As Byte) As Byte
Dim btBuf As Byte
Dim lngK As Long
For lngK = LBound(bt) To UBound(bt)
btBuf = btBuf Xor bt(lngK)
Next
XORByteArray = btBuf
End Function
Public Sub test()
Dim bt(0 To 34) As Byte
'[21] [00]
'[00][00][7f][ff][7f][ff][00][00][00][00][00][00][00][00][00][00]
'[00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]
'[03]
'[22] <---checksum
bt(0) = &H21
bt(4) = &H7F
bt(5) = &HFF
bt(6) = &H7F
bt(7) = &HFF
bt(34) = &H3
Debug.Print "[" & Hex$(XORByteArray(bt)) & "]"
End Sub
==========
--
Paul Marshall
pmarshal@vulcraft-al.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks