숫자를 hex 코드로 변환
/* print input in hex */ void print_hex( int input ){ int var, i; int len = 0; char buf[255]; do{ var = input % 16; input /= 16; /* try to convert ascii code */ if( var<10 ) buf[len] = var+48; else buf[len] = var+55; len++; }while( input>0 ); /* bigger than 16? then try again */ /* print reversely */ for ( i=len; i>0; i-- ) putchar( buf[i-1] ); putchar( '\n' ); } int main( int argc, char** argv ){ int input; printf( "input number: " ); scanf( " %d", &input ); /* print hex with printf */ printf( "%x\n", input ); /* print hex with my function */ print_hex( input ); return 0; }