Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.0 KiB

  1. /******************************************************************************\
  2. * *
  3. * XTOA.C - Digit to string convertion functions. *
  4. * *
  5. * Copyright (c) C-Cube Microsystems 1996 *
  6. * All Rights Reserved. *
  7. * *
  8. * Use of C-Cube Microsystems code is governed by terms and conditions *
  9. * stated in the accompanying licensing statement. *
  10. * *
  11. \******************************************************************************/
  12. static char digits[] = "0123456789ABCDEF";
  13. char *_itoa( unsigned int value, char *string, unsigned int radix )
  14. {
  15. char result[265];
  16. int pos;
  17. int index;
  18. int dig;
  19. pos = 0;
  20. do
  21. {
  22. dig = value % radix;
  23. //if ( dig )
  24. result[pos++] = digits[dig];
  25. value -= dig;
  26. dig = value / radix;
  27. value = dig;
  28. } while ( dig >= (int)radix );
  29. if ( dig )
  30. result[pos++] = digits[dig];
  31. /*
  32. if ( pos == 0 )
  33. result[pos++] = '0';
  34. */
  35. result[pos] = 0;
  36. index = 0;
  37. do
  38. {
  39. string[index++] = result[--pos];
  40. } while( pos );
  41. string[index] = 0;
  42. return string;
  43. }
  44. char *_ltoa( unsigned long value, char *string, unsigned long radix )
  45. {
  46. char result[265];
  47. int pos;
  48. int index;
  49. long dig;
  50. pos = 0;
  51. do
  52. {
  53. dig = value % radix;
  54. //if ( dig )
  55. result[pos++] = digits[dig];
  56. value -= dig;
  57. dig = value / radix;
  58. value = dig;
  59. } while ( dig >= (int)radix );
  60. if ( dig )
  61. result[pos++] = digits[dig];
  62. /*
  63. if ( pos == 0 )
  64. result[pos++] = '0';
  65. */
  66. result[pos] = 0;
  67. index = 0;
  68. do
  69. {
  70. string[index++] = result[--pos];
  71. } while( pos );
  72. string[index] = 0;
  73. return string;
  74. }