Documente Academic
Documente Profesional
Documente Cultură
Algoritmo informtico
Perl
# Clculo del dgito de control EAN my $ean = '123456789041'; my $checksum = 1000; my $i = 0; for my $digit (split //, reverse $ean) { forma inversa, dgito por dgito # Valor de prueba
# Recorremos el $ean de
European Article Number $checksum -= $i++ % 2 dgito: ? $digit : $digit*3 ; } $checksum %= 10; inmediatamente inferior print "Dgito de control: $checksum\n"; print "Cdigo EAN: $ean$checksum\n"; # Modificamos $checksum # segn la posicin del # posicin impar # posicin par
# Ajustamos a la decena
PHP
// Clculo del dgito de control EAN function ean13_checksum ($message) { $checksum = 0; foreach (str_split(strrev($message)) as $pos => $val) { $checksum += $val * (3 - 2 * ($pos % 2)); } return ((10 - ($checksum % 10)) % 10); } // Valor de prueba (sin dgito de control) $ean = '931804231236'; echo 'Digito de control: ', ean13_checksum($ean);
C#
// Clculo del dgito de control EAN int iSum = 0; int iSumInpar = 0; int iDigit = 0; string EAN = "123456789041"; // 12 digitos unicamente EAN=EAN.PadLeft(13,'0'); for (int i = EAN.Length; i >= 1; i--) { iDigit = Convert.ToInt32(EAN.Substring(i - 1, 1)); if (i % 2 != 0) { iSumInpar += iDigit; } else { iSum += iDigit;
European Article Number } } iDigit = (iSumInpar*3) + iSum ; int iCheckSum = (10 - (iDigit % 10)) % 10; Console.Write("Digito de control: " + iCheckSum.ToString());
Python
EAN = "123456789041" def eanCheck(ean): checksum = 0 for i, digit in enumerate(reversed(ean)): checksum += int(digit) * 3 if (i % 2 == 0) else int(digit) return (10 - (checksum % 10)) % 10 print "Digito de control: %d" %eanCheck(EAN)
Visual Basic
'Clculo del dgito de control EAN Dim iSum As Integer = 0 Dim iDigit As Integer = 0 Dim EAN As String = "123456789041"
'EAN de prueba
For i As Integer = EAN.Length To 1 Step -1 iDigit = Convert.ToInt32(EAN.Substring(i - 1, 1)) If (EAN.Length - i + 1) Mod 2 <> 0 Then iSum += iDigit * 3 Else iSum += iDigit End If Next Dim iCheckSum As Integer = (10 - (iSum Mod 10)) Mod 10 Console.Write("Dgito de control: " & iCheckSum.ToString())
JAVASCRIPT
// Clculo del dgito de control EAN function ean13_checksum(message) { var checksum = 0; message = message.split('').reverse(); for(var pos in message){ checksum += message[pos] * (3 - 2 * (pos % 2)); }
European Article Number return ((10 - (checksum % 10 )) % 10); } // Valor de prueba (sin dgito de control) var ean = '123456789041'; console.log(ean13_checksum(ean));
ABAP
CALL FUNCTION 'MARA_EAN11' EXPORTING P_MATNR = MARA-MATNR P_NUMTP = MARA-NUMTP P_EAN11 = MARA-EAN11 P_MEINH = MARA-MEINS RET_EAN11 = LMARA-EAN11 RET_NUMTP = LMARA-NUMTP BINPT_IN = SY-BINPT P_MESSAGE = ' ' ERROR_FLAG = EAN_FEHLERFLG P_HERKUNFT = 'A' " Fr Abmessungen / EAN GDS_RELEVANT = MARA-GDS_RELEVANT IMPORTING P_NUMTP = MARA-NUMTP P_EAN11 = MARA-EAN11 VB_FLAG_MEAN = RMMG2-VB_MEAN MSGID = MSGID " s. weiter unten MSGTY = MSGTY MSGNO = MSGNO MSGV1 = MSGV1 MSGV2 = MSGV2 MSGV3 = MSGV3 MSGV4 = MSGV4 TABLES MARM_EAN = MARM_EAN MEAN_ME_TAB = MEAN_ME_TAB " NEU: AHE 24.10.95 ME_TAB = ME_TAB YDMEAN = YDMEAN EXCEPTIONS EAN_ERROR = 1 OTHERS = 2....
Delphi
// Clculo del dgito de control EAN function cc_CalcDV_Ean(Ean: String): Integer; overload; { Calcula y devuelve el dgito verificador de una cadena de cdigo EAN13 o EAN8 Devcuelve -1 en caso de ser incorrecto. } var
European Article Number SP, SI, I, L:Integer; Impar: Boolean; begin L:= Length(Ean); if (L=8) or (L=13) then begin SI:= 0; SP:= 0; I:= L-1; Impar:= True; repeat // Bucle para sumar los valores discriminando posiciones pares e impares if Impar then SI:= SI + StrToInt(Ean[I]) else SP:= SP + StrToInt(Ean[I]); Impar:= not Impar; I:= I - 1; until I =0; if Impar then SI:= SI*3 else SP:= SP*3; // Multiplica por tres segn la longitud del cdigo Result:= 10-(SI+SP) mod 10; // Calcula el dgito de verificacin end else Result:= -1; end;
Referencias
[1] http:/ / www. gs1. org/ barcodes/ support/ prefix_list [2] 10 Pasos para implantar el Cdigo de Barras (http:/ / www. aecoc. es/ aecoc/ admin/ web/ gc_search. php?entidad=13& tipo=3& Id=605)
Enlaces externos
Simplemente Cdigos de Barras (http://www.codigoean.com) EAN International, ahora GS1 International (http://www.gs1.org) (en ingls) Directorio de sitios en todo el mundo (http://www.gs1.org/countries/alphabetically) Prefijos EAN por pas (http://www.gs1.org/barcodes/support/prefix_list) EAN database (http://www.ean-search.org) (en ingls)
Licencia
Creative Commons Attribution-Share Alike 3.0 //creativecommons.org/licenses/by-sa/3.0/