home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / SMALL_C / ITOX.C < prev    next >
Text File  |  1987-10-04  |  640b  |  23 lines

  1. /*
  2. ** itox -- converts nbr to hex string of length sz
  3. **         right adjusted and blank filled, returns str
  4. **
  5. **        if sz > 0 terminate with null byte
  6. **        if sz = 0 find end of string
  7. **        if sz < 0 use last byte for data
  8. */
  9. itox(nbr, str, sz)  int nbr;  char str[];  int sz;  {
  10.   int digit, offset;
  11.   if(sz>0) str[--sz]=0;
  12.   else if(sz<0) sz = -sz;
  13.   else while(str[sz]!=0) ++sz;
  14.   while(sz) {
  15.     digit=nbr&15; nbr=(nbr>>4)&4095;
  16.     if(digit<10) offset=48; else offset=55;
  17.     str[--sz]=digit+offset;
  18.     if(nbr==0) break;
  19.     }
  20.   while(sz) str[--sz]=' ';
  21.   return str;
  22.   }
  23.