求EAN_13 条形码 最后一位的算法

来源:百度知道 编辑:UC知道 时间:2024/07/01 02:15:43
求EAN_13 条形码 最后一位的算法

我以前写的程序,你自己看吧. :)

void BarcodeEAN13CalculateCheckDigit(char *a_src, char *a_newSrcBuf, int *a_CheckSum)
{
char tmpBuf[256];

char *pSrc = a_src;
char *pDest = tmpBuf;

long count=0;
long checkSum=0;

int sum1=0, sum2=0, checkFlag=0;

//make sure 12th character is \0, EAN13 the info is from 0-11, 12th is checkdigit
a_src[12] = _T('\0');

//calculate check digits
//Consider the right-most digit of the message to be in an "odd" position, and assign odd/even to each character moving from right to left.
//Sum the digits in all odd positions, and multiply the result by 3.
//Sum the digits in all even positions.
//Sum the totals calculated in steps 2 and 3.
//The check digit is the number which, when added to the totals calculated in step 4, result in a number evenly divisible by 10.
//If the sum cal