ASTM checksum
- From: Spin <cNaOlSePbA@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 11:50:04 -0600
Could I have some help calculating a checksum for data transmission to a lab machine? Here are the ASTM specs for the checksum:
The checksum is computed by adding the binary values of the characters, keeping the least significant eight bits of the result. Each character in the message text is added to the checksum (modulo 256). The checksum is an integer represented by eight bits, it can be considered as two groups of four bits. The groups of four bits are converted to the ASCII characters of the hexadecimal representation. The two ASCII characters are transmitted as the checksum, with the most significant character first.
This is a sample message, where '40' is the checksum and the checksum is calculated using the 7 through to the <ETX>:
<STX>7L|1|N<CR><ETX>40<CR><LF>
Thus the checksum is calculated with this portion of the string: 7L|1|N<CR><ETX>
Of course the <CR> and <ETX> are sent as chr(13) and chr(03), not as they appear in the email here.
I have been working with unpack and the % operator but to no avail.
TIA Spin .
- Follow-Ups:
- Re: ASTM checksum
- From: usenet
- Re: ASTM checksum
- Prev by Date: Re: substr forces scalar context with array argument
- Next by Date: Re: ASTM checksum
- Previous by thread: substr forces scalar context with array argument
- Next by thread: Re: ASTM checksum
- Index(es):
Relevant Pages
|