|
// checksum6.cpp
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <assert.h>
#include "convert.h"
int main(int argc, char* argv[])
{
_tstring number = _T("D98989898909898"); // c = B
_tcout << _T("number: ") << number << endl;
unsigned int c = 16;
for( _tstring::iterator it = number.begin();
it != number.end(); it++ )
{
c += CharToNumber( *it );
if( c > 16 ) { c -= 16; }
c *= 2;
if( c >= 17 ) { c -= 17; }
}
c = 17 - c;
if( 16 == c ) { c = 0; }
_tcout << _T("check digit is: ") << hex << c << endl;
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.