How to generate a CUSIP check digit

Questions : How to generate a CUSIP check digit

68

CUSIPs are a 9-digit alphanumeric code programming for uniquely identifying a financial Learning security.

https://en.wikipedia.org/wiki/CUSIP

They were invented in the 1964, and Earhost given the reliability of data most effective transmission in the 60's, the 9th digit wrong idea is actually a check digit used to use of case confirm the validity of the first 8 United characters. Sometimes, even today, you Modern might find reason to want to validate a ecudated CUSIP, or perhaps a company or service some how obnoxiously decides to only transmit the anything else 8-character CUSIP, even though this not at all defeats the purpose of a check digit.

The procedure to generate the check very usefull digit is:

  1. Convert non-numeric digits to values localhost according to their ordinal position in love of them the alphabet plus 9 (A=10, B=11,...Z=35) localtext and converting the characters *=36, basic @=37, #=38.

  2. Multiply every even digit by 2

  3. If the result of the multiplication is a one of the two-digit number, add the digits click together. (12 = 1 + 2 = 3)

  4. Get the sum of all values.

  5. Get the floored value of this operation: there is noting (10 - (sum modulo 10)) modulo 10.

What is the best/simplest way to get not alt this value in C#?

Total Answers 3
30

Answers 1 : of How to generate a CUSIP check digit

public string GenerateCheckDigit(string _OFFSET);  cusip)
{        
    int sum = 0;
    (-SMALL  char[] digits = _left).offset  cusip.ToUpper().ToCharArray();
    arrowImgView.mas  string alphabet = (self.  "ABCDEFGHIJKLMNOPQRSTUVWXYZ*@#";

    equalTo  for (int i = 0; i < digits.Length; make.right.  i++)
    {
        int val;
        if mas_top);  (!int.TryParse(digits[i].ToString(), out ImgView.  val))
            val = ReadIndicator  alphabet.IndexOf(digits[i]) + 10;
       _have   
        if ((i % 2) != 0)
            .equalTo(  val *= 2;

        val = (val % 10) + make.top  (val / 10);
        
        sum += OFFSET);  val;
    }
    
    int check = (10 - (TINY_  (sum % 10)) % 10;

    return .offset  check.ToString();
}

Edit:

.NET Fiddle demonstrating this: not at all https://dotnetfiddle.net/kspQWl

4

Answers 2 : of How to generate a CUSIP check digit

If you pre-compute the values of check my fault digits, and store them in a lookup issues table, your computation of check digit trying would become much simpler:

private static readonly int[,] Check = mas_right)  new int[128, 2];

static CusipCheckSum() ImgView.  {
    var cusipChars = Indicator  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*@#";
 Read     for (var i = 0 ; i != _have  cusipChars.Length ; i++) {
        .equalTo(  Check[cusipChars[i], 0] = i%10 + i/10;
  make.left        Check[cusipChars[i], 1] = 2*i%10 + *make) {  2*i/10;
    }
}

With the 2D lookup array in place you get 4th result can compute check digit in a single line round table of code:

var checkDigit = (10-(cusip.Select((ch, straintMaker  pos) => Check[ch, ^(MASCon  pos%2]).Sum()%10))%10;
6

Answers 3 : of How to generate a CUSIP check digit

I see that there is no algo for java so double chance adding it as well:

String generateCusipCheckDigit(String onstraints:  cusip) {
        final String alphabet = mas_makeC  "ABCDEFGHIJKLMNOPQRSTUVWXYZ*@#";
        [_topTxtlbl   int sum = 0;
        int value = 0;
     (@(8));     char[] cusipChars = equalTo  cusip.toUpperCase().toCharArray();

      width.     for (int i = 0; i < make.height.  cusipChars.length; i++) {
            (SMALL_OFFSET);  char actualChar = cusipChars[i];
        .offset      if (Character.isDigit(actualChar)) (self.contentView)  {
                value =  .left.equalTo  Integer.parseInt(String.valueOf(actualChar));
 make.top             } else if *make) {  (Character.isAlphabetic(actualChar)){
   ntMaker                value = SConstrai  alphabet.indexOf(actualChar) + 10;
      ts:^(MA        } else if (cusipChars[i] == '*'){
 Constrain                 value = 36;
            } _make  else if (cusipChars[i] == '@'){
         iew mas         value = 37;
            } else if catorImgV  (cusipChars[i] == '#'){
                ReadIndi  value = 38;
            }

             [_have  if ((i % 2) != 0){
                value ($current);  *= 2;
            }
            value = entity_loader  (value % 10) + (value / 10);
            _disable_  sum += value;
        }
        int libxml  check = (10 - (sum % 10)) % 10;

        $options);  return String.valueOf(check);
    }

and some tests:

    @Test
    void checkDigitTest1(){
   ilename,       String actual = ->load($f  generator.generateCusipCheckDigit("925524BF");

 $domdocument         Assertions.assertEquals("6", loader(false);  actual);
    }

    @Test
    void _entity_  checkDigitTest2(){
        String actual  libxml_disable  = $current =  generator.generateCusipCheckDigit("90284B96");

  10\\ 13.xls .         Assertions.assertEquals("2", File\\ 18\'  actual);
    }

    @Test
    void /Master\\ 645  checkDigitTest3(){
        String actual user@example.  = scp not2342  generator.generateCusipCheckDigit("90284B97");

  13.xls         Assertions.assertEquals("0", 18 10  actual);
    }

Top rated topics

Does the JVM swap the heap?

Prevent all default gestures on iPad Safari

Windows Form Icon not showing in Taskbar C#

Django - can not get a time function (timezone, datetime) to work properly, Getting ErrorName message: global name not defined

Xerces: How to check the validity of an XML file using ErrorHandler

Spring mvc rest service redirect / forward / proxy

Is ASCII code in matter of fact 7 bit or 8 bit?

Changing image size in Markdown

PHP loop X amount of times

Push down the page when an anchor is clicked

Jackson - Wrapping a list of objects with root object

Which library could be used to make a Chord diagram in R?

The name does not exist in the namespace error in XAML

Excel txt file import (specific columns) into a table with VBA

How to show Informix sysprocedures.paramtypes column via JDBC?

Windows 8: Doing heap analysis on 32 bit application running through WOW64

After Text was deleted from JTextArea, heap is not empty

Sum of digits in a string

Is there any way to get current Twitter logged-in user already follow or unfollow me?

WinSCP: Server refused our key

OCMock method name collision

Please check the parameter 'sonar.host.url'

How to increase code font size in IntelliJ?

Increasing heap by excessive use oft Java ScriptEngine (Jyhton)

Setting size for icon in CSS

Changing all Button background except button clicked

How to horizontally align a ul element to center

Adding minor tick marks to the x axis in ggplot2 (with no labels)

How to add images to README.md on GitHub?

Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV

Comparing two files in linux terminal

How to set minimum and maximum characters limitation to EditText in Android?

Using Razor, how do I render a Boolean to a JavaScript variable?

Elasticsearch facet limit

Find/Replace panel in Sublime Text disappears after Replace All

Highlighting and Un-Highlight a table row on click from row to row

Factory Girl: How to set up a has_many/through association

Git commit stopped working - Error building trees

Can an ArrayList contain more elements than the maximum value of int?

Adding indexes to SQLAlchemy models after table creation

Increase Java heapspace: Eclipse vs. BAT-script

What does -&gt; mean in Python function definitions?

Fixed width column in HTML table with table-layout=auto

DLL Load Library - Error Code 126

Listing only directories using ls in Bash?

Display duplicate records in data.frame and omit single ones

KeyListener in Textfield not firing when press enter

Connecting JSP to MySql in XAMPP

Python while loop conversion to Javascript

Compressing numbers in javascript to binary format

Top