Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const char __stdlib_int_to_hex_table[16] =
- {
- '0', '1', '2', '3','4','5','6','7','8','9','a','b','c','d','e','f',
- };
- // lower case
- // size of `buf` must be enough for 'ffffffffffffffff' so buf[16]
- char __CRT_itoa_internalBuffer[30]; // need to fix itoa(123) = "321"
- void
- __CRT_dectohex(uint64_t dec, char* buf, int* sz)
- {
- if (dec)
- {
- double decInDouble = (double)dec;
- int bufInd = 0;
- while (1)
- {
- decInDouble /= 16.0;
- double ipart = 0.0;
- int i = (int)(modf(decInDouble, &ipart) * 16.0);//(dec % 16) * 16;
- dec /= 16; // for exit from loop
- __CRT_itoa_internalBuffer[bufInd++] = __stdlib_int_to_hex_table[i];
- if (!dec)
- break;
- }
- *sz = bufInd;
- if (bufInd)
- {
- for (int i = 0; i < bufInd; ++i)
- {
- buf[i] = __CRT_itoa_internalBuffer[bufInd - i - 1];
- }
- buf[bufInd] = 0;
- }
- }
- else
- {
- buf[0] = '0';
- buf[1] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement