|
#include "StdAfx.h"
#include <assert.h>
int CharToNumber( TCHAR c )
{
switch ( c )
{
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case 'a': case 'A': return 10;
case 'b': case 'B': return 11;
case 'c': case 'C': return 12;
case 'd': case 'D': return 13;
case 'e': case 'E': return 14;
case 'f': case 'F': return 15;
default: ;
}
return -1;
}
TCHAR NumberToChar( int d )
{
_tostringstream oss( _tostringstream::out );
oss << hex << d << std::ends;
return oss.str()[0];
}
int StringToNumber( _tstring s )
{
_tistringstream ss( s );
int n;
ss >> n;
return n;
}
_tstring NumberToString( int n )
{
_tostringstream oss( _tostringstream::out );
oss << n << std::ends;
return oss.str();
}
/*
_tstring NumberToString( double d )
{
_tostringstream oss( _tostringstream::out );
oss.setf(std::ios::fixed);
oss.precision(4);
oss << d << std::ends;
return oss.str();
}
*/
|
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.