IntToString.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Common/IntToString.cpp
  2. #include "StdAfx.h"
  3. #include "IntToString.h"
  4. void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)
  5. {
  6. if (base < 2 || base > 36)
  7. {
  8. *s = '\0';
  9. return;
  10. }
  11. char temp[72];
  12. int pos = 0;
  13. do
  14. {
  15. int delta = (int)(value % base);
  16. temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));
  17. value /= base;
  18. }
  19. while (value != 0);
  20. do
  21. *s++ = temp[--pos];
  22. while(pos > 0);
  23. *s = '\0';
  24. }
  25. void ConvertUInt64ToString(UInt64 value, wchar_t *s)
  26. {
  27. wchar_t temp[32];
  28. int pos = 0;
  29. do
  30. {
  31. temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));
  32. value /= 10;
  33. }
  34. while (value != 0);
  35. do
  36. *s++ = temp[--pos];
  37. while(pos > 0);
  38. *s = L'\0';
  39. }
  40. void ConvertInt64ToString(Int64 value, char *s)
  41. {
  42. if (value < 0)
  43. {
  44. *s++ = '-';
  45. value = -value;
  46. }
  47. ConvertUInt64ToString(value, s);
  48. }
  49. void ConvertInt64ToString(Int64 value, wchar_t *s)
  50. {
  51. if (value < 0)
  52. {
  53. *s++ = L'-';
  54. value = -value;
  55. }
  56. ConvertUInt64ToString(value, s);
  57. }