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


Windows technical support
Podporni forum za uporabnike storitev spletnega gostovanja
Reply to topic
Calculate MOD11 control number
Pico
Site Admin

Joined: 18 Jan 2004
Posts: 250
Location: HostMachine.net
Reply with quote
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:
Code:
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.
View user's profileSend private messageVisit poster's websiteMSN Messenger
Calculate MOD11 control number
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT + 1 Hour  
Page 1 of 1  

  
  
 Reply to topic