- or download this
#! perl -slw
use strict;
...
?9999FF1B? : 0
?9998FF1B? : 1
- or download this
9999 = 57 + 57 + 57 + 57 = 228.
~ 228 = -229 decimal = FF1B hex (16-bit)
Add the header and trailer characters = <SOH>9999FF1B<ETX>
- or download this
1 + 57 + 57 + 57 + 57 = 229
- or download this
FF1B = 65307
- or download this
(65307 + 229) = 65536
65536 & 65535 = 0x10000 & 0xFFFF = 0
- or download this
sub build_string {
my( $string ) = @_;
...
return chr(1) . $string . sprintf( '%4x', $chksum ) . chr(3);
}