Recent work involving computingBar CodeBatch change of 13th-bit check bits,AI,Bar Code printer,Barcode ScannerAnd other built-in software to generate a checkpoint.Bar Code GeneratorBut it is not flexible enough for us to write a small program to calculate the check bit.
Okay. Let's take a look at the PHP version first. It's a lot easier to find on the Internet.
Function en13 ($ code) {$ tmp1 = 0; $ tmp2 = 0; For ($ I = 0; $ I <12; $ I ++) {if ($ I % 2 = 0) $ tmp1 + = substr ($ code, $ I, 1); else $ tmp2 + = substr ($ code, $ I, 1);} return (10-($ tmp2 * 3 + $ tmp1) % 10) % 10;} // test $ T = "6939762911740 "; echo en13 ($ t );
In addition, if you want to update the data in the MSSQL database in batches, you do not need to write programs. Instead, you can directly update the data in the SQL Enterprise Manager.
T-SQL code
declare @str as varchar(15)declare @tmp as varchar(30)declare @t1 as intdeclare @t2 as intdeclare @i int set @t1=0set @t2=0set @str='6939762911740'set @i=1 while @i<=12 begin if @i % 2=0 beginset @t1=@t1+substring(@str,@i,1)endelsebeginset @t2=@t2+substring(@str,@i,1)endset @i=@i+1 endset @tmp=(10-(@t1*3+@t2)%10)%10--end functionSELECT @t1 ,@t2,@tmp
ENA-13 verification code calculation method code position serial number refers to including the checkcode, from right to left Sequential Number (checkcode code position serial number is 1 ). The verification code is calculated as follows: A. The sum of all the even numbers starting from the code position 2. B. Multiply the sum of step a by 3. C. sum the numeric codes of all odd digits starting from code position 3. D. Add the result of step B and Step C. E. Subtract the result from step d with a number greater than or equal to step d and a minimum integer multiple of 10. The difference is the value of the obtained verification code. Example: The Code 690123456789x1 is calculated in table 1. Table 1
Steps for calculating the Verification Code are as follows: 1. from right to left sequence number position No. 13 12 11 10 9 8 8 6 5 5 4 3 2 1 Code 6 9 0 1 2 3 4 5 6 7 8 9x2. start from number 2 and find the sum of numbers in the even bits ① 9 + 7 + 5 + 3 + 1 + 9 = 34 ① 3. ① * 3 = ② 34 × 3 = 102 ② 4. calculate the sum of numbers in the odd digit (3) 8 + 6 + 4 + 2 + 0 + 6 = 26 (3) 5. ② + ③ = ④ 102 + 26 = 128
④ 6. Subtract ④ from a number greater than or equal to result ④ and a 10 smallest integer multiple. The difference is the value of the checkcode 130-128 = 2 checkcode X1 = 2