Barcode

It has certainly happened to you once, when paying something at the cash of the supermarket, that the barcode reader machine is unable to read the code of some product. What happened then? The cashier wrote the barcode number in the computer keyboard. But sometimes the cashier can make some mistake and write a wrong number (that might correspond to a different product, with a different price...), no? Well, in that case the computer will detect the error and will produce some alert message (usually, some warning sound).

After all, what makes the computer system detect the error? Simply, the existence of a check digit in the barcode.

How is it calculated the check digit?