ISIN Check

International Securities Identification Number (ISIN) see Double-Add-Double Implentation

/**
* Calculates the Double-Add-Double from String src (length 11 chars) 
* alternatively checks validity (length 12 chars, result 0 if valid else undefinied.
*/
public static int calculateCheckISIN(String src)
{
  int  result = 0;
  int  whatLength = (src.length() == 12)? 1 : 2;
  int  current;
  for(int i = src.length() - 1; i >= 0; i--)
  {
    current = src.charAt(i);
    if(current > '9')
    {
      // It is a char
      current -= ('A' - 10);
      result += (3-whatLength)*(current/10) + whatLength*current + (whatLength-1)*(current%10)/5;
    }
    else
    {
      // It is a numeric character
      current -= '0';
      result += whatLength*current + (whatLength-1)*(current/5);
      whatLength = 3 - whatLength;
    }
  }
  result %= 10;
  result = (10 - result%10) % 10;
  return result;
}

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.