Post Reply 
Barcode generator
05-06-2024, 12:25 PM (This post was last modified: 05-06-2024 12:26 PM by ThomasF.)
Post: #5
RE: Barcode generator
(05-04-2024 07:06 PM)Benoit Maag Wrote:  Also, I am trying to understand the checksum algorithms but the HP documentation is not very clear - is there a simple explanation somewhere?


Hi,

The algorithm is fairly easy, for most bar codes the first byte is a 8-bit checksum of all bytes in the code:

Code:
    int chkSum = firstLine ? 0 : prevLineChecksum;
    for(int n=1; n<bLen; n++) // Loop over all bytes (except the first one)
        chkSum += barcode.bytes[n];
    while( chkSum & 0xFF00 ) // Check if any overflow
        chkSum = (chkSum&0xFF) + (chkSum>>8);
    barcode.bytes[0] = chkSum; // Save the checksum in the array
bLen is the length of the array holding the bytes, and barcode.bytes is the array.
barcode.bytes[0] will contain the calculated checksum.

For program bar codes (multiple lines), the checksum is initialized with zero (0) for the first line, and for all other lines the checksum is initialized to the checksum of the previous line (a running checksum).

The exception are paper keyboard bar codes.
- The one-byte bar codes which has no checksum, instead the second nibble is the same as the first but reversed (e.g. hex "DB" = binary "1101 1011").
- And two bytes codes, where the checksum is only 4 bits (nibble[0]) and is the 4-bit checksum of the other three nibbles.

Hope that clear up any confusion ... Wink

Cheers,
Thomas

[35/45/55/65/67/97/80 21/25/29C 31E/32E/33E|C/34C/38E 41C|CV|CX 71B 10C/11C/12C/15C|CE/16C 32S|SII/42S 28C|S 48GX/49G/50G 35S 41X]
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Barcode generator - Benoit Maag - 05-04-2024, 07:06 PM
RE: Barcode generator - Didier Lachieze - 05-04-2024, 10:48 PM
RE: Barcode generator - Pierre - 05-05-2024, 06:53 AM
RE: Barcode generator - aurelio - 05-09-2024, 02:04 PM
RE: Barcode generator - Pierre - 05-09-2024, 10:07 PM
RE: Barcode generator - Benoit Maag - 05-05-2024, 02:32 PM
RE: Barcode generator - ThomasF - 05-06-2024 12:25 PM
RE: Barcode generator - Benoit Maag - 05-11-2024, 04:19 PM
RE: Barcode generator - Benoit Maag - 05-11-2024, 04:20 PM
RE: Barcode generator - Benoit Maag - 05-11-2024, 04:13 PM
RE: Barcode generator - Massimo Gnerucci - 05-11-2024, 05:42 PM
RE: Barcode generator - Pierre - 05-11-2024, 11:05 PM



User(s) browsing this thread: 1 Guest(s)