algorithm - PHP CUSIP Check num -
I should be able to validate CUSIP numbers based on my check digits. I have a psudocode for Wikipedia Thanksgiving process, but I am unable to repeat it in PHP yet.
Psudocode can be found.
My PHP:
& lt ;? Php / ** * Function to return the check digits value of a Cuisine * @Unimum $ cusip * cusip for processing. * @Ratn Int * Cusip Check Digit * / Function cusip_checksum ($ cusip) {$ sum = 0; $ Rebuiltcusip = ''; {$ C = substr ($ cusip, ($ i - 1), 1) for ($ I = 1; $ i & lt; = 8; $ i ++); // $ i needs to be 0, so as we start with 1, take away from 1 $ rebillectus = $ c; Switch (true) {case $ c == '0': // ctype_digit (0) wrong, so checking for 0. $ V = $ c; Watchdog ("Case 0:", $ V); break; Case ctype_digit ($ c): // check numeric $ v = $ c; Watchdog ("case ctype_digit:", $ v); break; Case $ c == '*': $ v = 36; Watchdog ("Case *:", $ V); break; Case $ c == '@': $ v = 37; Watchdog ("Case @:", $ V); break; Case $ c == '#': $ v = 38; Watchdog ("Case #:", $ V); break; Case! Ctype_digit ($ c): // In the final form of check check, it passes through check * @ or # so that they first get $ v = (ord ($ c) - 64) + 9; // Set serial number, -64 as it returns the ASKII value, then add 9. DocDog ("not case ctype_digit:", $ v); break; } If (($ i% 2) == 0) {// Check Weird $ v = $ v * 2; Watchdog ("Weird Case:", $ V); } $ Sum = $ sum + ($ v / 10) + ($ v% 10); Watchdog ("sum end loop:", $ sum); } $ Ncd = (10 - ($ sum% 10))% 10; $ Rebelt cease = $ NCD; Watchdog ("Recycled Cushhip:", "Cuisine:". Cusip. "Rebuild:". $ Rebuiltcusip); Return $ NCD; }? & Gt; Watchdog is just process logging me
Passing in a CUSIP: 98 9 86 T 108 with a check number of 8, in fact 98986 T104 Returns the value (check the 4 digit digits).
Like this:
& lt ;? Php print cusip_checksum ('98986T108'); ? & Gt; split in the floor () function Wrap and you are there: $ sum = $ sum + floor ($ v / 10) Post-less "itemprop =" text "> + ($ V% 10) ;
Now the QISP will have a value of Q 26. It will add 2.6 and 6 instead of 2 to 6.
The work I have run through the removal of a 17614 CUSP Writer and 11 which were not in the match. It is usually visible from Reuters data The error is about the level of error, so I believe in the routine. / ** * Function to return the value of the check digits of a cusip * @ the ultimate $ cusip * processing For cusip * @ reton int * qusip check digit * / function cusip_checksum ($ cusip) {$ sum = 0; $ Rebuiltcusip = ''; ($ I = 1; $ i & lt; = 8; $ i ++) For {$ c = substr ($ cusip, ($ i - 1), 1); // $ i needs to be 0, so as we start with 1, take away 1 from $ rebillectus = $ c ; Switch (true) {case $ c == '0': // ctype_digit (0) returns wrong, isl Checking for 0. $ V = $ c; Watchdog ("Case 0:", $ V); break; Case ctype_digit ($ c): // check numeric $ v = $ c; Watchdog ("case ctype_digit:", $ v); break; Case $ c == '*': $ v = 36; Watchdog ("Case *:", $ V); break; Case $ c == '@': $ v = 37; Watchdog ("Case @:", $ V); break; Case $ c == '#': $ v = 38; Watchdog ("Case #:", $ V); break; Case! Ctype_digit ($ c): // In the final form of check check, this will pass through @ * @ or check, so that they first get $ v = (ord ($ c) - 64) + 9; // Set serial number, -64 as it returns the ASKII value, then add 9. DocDog ("not case ctype_digit:", $ v); break; } If (($ i% 2) == 0) {// Check Weird $ v = $ v * 2; Watchdog ("Weird Case:", $ V); } $ Sum = $ sum + floor ($ v / 10) + ($ v% 10); Watchdog ("sum end loop:", $ sum); } $ Ncd = (10 - ($ sum% 10))% 10; $ Rebelt cease = $ NCD; Watchdog ("Recycled Cushhip:", "Cuisine:". Cusip. "Rebuild:". $ Rebuiltcusip); Return $ NCD; }
Comments
Post a Comment