|
#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;
case 'g': case 'G': return 16;
case 'h': case 'H': return 17;
case 'i': case 'I': return 18;
case 'j': case 'J': return 19;
case 'k': case 'K': return 20;
case 'l': case 'L': return 21;
case 'm': case 'M': return 22;
case 'n': case 'N': return 23;
case 'o': case 'O': return 24;
case 'p': case 'P': return 25;
case 'q': case 'Q': return 26;
case 'r': case 'R': return 27;
case 's': case 'S': return 28;
case 't': case 'T': return 29;
case 'u': case 'U': return 30;
case 'v': case 'V': return 31;
case 'w': case 'W': return 32;
case 'x': case 'X': return 33;
case 'y': case 'Y': return 34;
case 'z': case 'Z': return 35;
default: assert( false );
}
return -1;
}
TCHAR NumberToChar( int d )
{
if( d >= 0 && d <= 9 ) { return d + '0'; }
if( d >= 10 && d <= 35 ) { return d - 10 + 'A'; }
return 0x00;
}
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.