Veď postupuj tak, ako si na to išiel pri prevode do dvojkovej:
Kód:
void hex( int a ) {
int remainder;
if ( a <= 9 ) {
cout << a;
return;
}
if ( ( a < 16 ) && ( a > 9 ) ) {
cout << static_cast< char >( 'A' + ( a - 10 ) );
return;
}
remainder = ( a % 16 );
hex( a >> 4 );
if ( ( remainder < 16 ) && ( remainder > 9 ) )
cout << static_cast< char >( 'A' + ( remainder - 10 ) );
else
cout << remainder;
}