December 04, 2020, 11:41:38 AM

Author Topic: [bmx] Calculate UPC-A Check Digit by daaan [ 1+ years ago ]  (Read 581 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Calculate UPC-A Check Digit
Author : daaan
Posted : 1+ years ago

Description : I had to do this for work and thought I'd share.

Code :
Code: BlitzMax
  1. Function CalcCheckDigit_UPCA:String(UPC:String="")
  2.        
  3.         Local CheckDigit:Int = 0
  4.        
  5.         For i:Int = 0 Until UPC.Length
  6.                
  7.                 CheckDigit :+ (Chr(UPC[i]).ToInt() * (1 + 2 * (i Mod 2)))
  8.                
  9.         Next
  10.        
  11.         Return (UPC+(10-(CheckDigit Mod 10)))
  12.        
  13. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal