Gostovanje na Windows strežnikih, ponudba webhosting, ASP.NET, PHP, MySQL


Windows tehnična podpora
Podporni forum za uporabnike storitev spletnega gostovanja
Odgovori na to temo
Calculate MOD11 control number
Pico
Site Admin

Pridružen/-a: Ned Jan 2004 0:15
Prispevkov: 230
Kraj: HostMachine.net
Odgovori s citatom
Many banks use MOD 11 algorithm to calculate control number for verification whether the main number is correct or not, mostly to avoid input errors when typing.
Also, many reference numbers on bills or invoices use the same MOD11 algorithm to be safe from user typografic errors.

MOD 11 principle:

- first, you split given number into separate cyphers, for example:
125111
is split into
1 2 5 1 1 1

- then you take each cypher, and multiply it with so called "ponder". First ponder is 2, then 3, 4, 5, 6, etc... You start multiplying from the RIGHT side, and then SUM all results, for example:
1x2 + 1x3 + 1x4 + 5x5 + 2x6 + 1x7 = 53

- then you DIVIDE final result by 11 (it is MOD11, that's why 11), for example:
53 / 11 = 4 (with reminder of 9)

- Finally, you take reminder of latest calculation and substract it from 11 (yes, 11 again), for example:
11 - 9 = 2

And 2 is control number in MOD11 operation.

Ok, let's calculate MOD11 with PHP script:
Koda:
function mod11($num) {
   $pond = 2;
   $sum = 0;
   $numRev = ereg_replace("[^0-9]", "", strrev($num));
   for($i=0;$i<strlen($numRev);$i++) {
      $currentNum = substr($numRev, $i, 1);
      $sum = $sum + (int)$currentNum * $pond;
      $pond++;
   }
   return 11-($sum-11*floor($sum/11));
}

_________________
Site admin alias Labsy
Vsi nasveti in tehnične rešitve so podani v dobri veri in za ljudi z razčiščenimi pojmi o veljavni zakonodaji.
Odgovornost prevzemam izključno in samo za tiste posege, ki jih opravim lastnoročno.
Poglej uporabnikov profilPošlji zasebno sporočiloObišči avtorjevo spletno stranMSN Messenger - naslov
Calculate MOD11 control number
Ne, ne moreš dodajati novih tem v tem forumu
Ne, ne moreš odgovarjati na teme v tem forumu
Ne, ne moreš urejati svojih prispevkov v tem forumu
Ne, ne moreš brisati svojih prispevkov v tem forumu
Ne ne moreš glasovati v anketi v tem forumu
Časovni pas GMT + 1 ura, srednjeevropski - zimski čas  
Stran 1 od 1  

  
  
 Odgovori na to temo