home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TTFHDX / CONVERT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  1.5 KB  |  81 lines

  1. /*
  2.  *    01/05/88    From Derek Mui.
  3.  */
  4.  
  5. /*    This routine convert binary number to ascii value    */
  6.  
  7. itoa(inword, numbuf)            
  8. unsigned int inword;
  9. char numbuf[];
  10. {    
  11.     unsigned int temp1, value;
  12.     register int i, j;
  13.     char tmpbuf[10];
  14.     register char *ascbuf;
  15.     
  16.     ascbuf = numbuf;
  17.     i = 0;                /* if the value is non zero  */
  18.  
  19.     if (!inword)    
  20.     *ascbuf++ = '0';
  21.     else {
  22.     value = inword;
  23.     while(value) {
  24.         temp1 = value % 10;        /*  find the remainder    */
  25.         temp1 += 0x0030;        /*  convert to ASCII    */
  26.         tmpbuf[i++] = temp1;    /*  buffer is reverse    */
  27.         value = value / 10;
  28.     }
  29.  
  30.     for (j = i-1; j >= 0; j--)     /* reverse it back    */
  31.         *ascbuf++ = tmpbuf[j];
  32.     }
  33.  
  34.     *ascbuf = 0;            /* end of string mark    */
  35.     return;
  36. }
  37.  
  38.  
  39. ltoa(inword, numbuf)            
  40. long inword;
  41. char numbuf[];
  42. {    
  43.     long temp1, value;
  44.     register int i, j;
  45.     char tmpbuf[10];
  46.     register char *ascbuf;
  47.     
  48.     ascbuf = numbuf;
  49.     i = 0;                /* if the value is non zero  */
  50.  
  51.     if (!inword)    
  52.     *ascbuf++ = '0';
  53.     else {
  54.     value = inword;
  55.     while(value) {
  56.         temp1 = value % 10;        /*  find the remainder    */
  57.         temp1 += 0x0030;        /*  convert to ASCII    */
  58.         tmpbuf[i++] = temp1;    /*  buffer is reverse    */
  59.         value = value / 10;
  60.     }
  61.  
  62.     for (j = i-1; j >= 0; j--)     /* reverse it back    */
  63.         *ascbuf++ = tmpbuf[j];
  64.     }
  65.  
  66.     *ascbuf = 0;            /* end of string mark    */
  67.     return;
  68. }
  69.  
  70.  
  71. atoi(ptr)
  72. char *ptr;
  73. {
  74.     register int n;
  75.  
  76.     for (n = 0; (*ptr >= '0' && *ptr <= '9'); ptr++)
  77.     n = (10 * n) + *ptr - '0'; 
  78.  
  79.     return (n);
  80. }
  81.