22
Mar
Unsigned long long (uint64) to string (ulltostr)
Related Blog Items
- Convert integer to binary string
- Unsigned long to string (ultostr)
- Binary Streams Utility Classes
- Structure padding explained
- c/c++ blogging - January 10, 2007
Here is the code snippet which does conversion from unsigned long long (uint64) to
string/ascii/char *.
it takes input as unsigned long long (uint64), converts it to string, it takes care of the base also.
example usage of function ulltostr is: ulltostr(1023234343453553, ptr, 10);
here is the code snippet….
#include <stdio.h> #ifdef _MSC_VER typedef unsigned __int64 uint64; #else typedef unsigned long long uint64 #endif char *ulltostr(uint64 value, char *ptr, int base) { uint64 t = 0, res = 0; uint64 tmp = value; int count = 0; if (NULL == ptr) { return NULL; } if (tmp == 0) { count++; } while(tmp > 0) { tmp = tmp/base; count++; } ptr += count; *ptr = '\0'; do { res = value - base * (t = value / base); if (res < 10) { * - -ptr = '0' + res; } else if ((res >= 10) && (res < 16)) { * - - ptr = 'A' - 10 + res; } } while ((value = t) != 0); return(ptr); }
please post your comments and suggestion if any….
Popularity: 12%
You need to log on to convert this article into PDF
Related Blog Items - Convert integer to binary string
- Unsigned long to string (ultostr)
- Binary Streams Utility Classes
- Structure padding explained
- c/c++ blogging - January 10, 2007
Related Blog Items
- Convert integer to binary string
- Unsigned long to string (ultostr)
- Binary Streams Utility Classes
- Structure padding explained
- c/c++ blogging - January 10, 2007
No Comments
No comments yet.