itoa

--------------------------------------------------------------------------------

can someone post how to implement itoa function for radix 16?

char* itoa(int value, char* buffer, int radix)
Erm.
itoa(myInt, myBuffer, 16);...
It just converts myInt into the given base (16) and stores it in buffer...
i was asking for how to implement that function if its not in our stdlib
thanks
closed account (S6k9GNh0)
petergrwl, that doesn't make sense. itoa is not in the standard specificationbut is implemented in most STD headers (I think?). Look into it.
Last edited on
It should be implemented in the std library source files -you can get the source of the gcc library-
itoa?

int i = 42;
cout << std::hex << i;

printf( "%x", i );
right, but if i=5, i want output to be 05, not just 5.
any ideas?

@bazzy, i couldnt find source, could you help? thanks
petergrwl : I posted a wikipedia site with an implementation, you can easily modify it to your needs.
int i = 5;
cout << std::setw( 2 ) << std::setfill ('0' ) << std::hex << i;

printf( "%02x", i );
Topic archived. No new replies allowed.