home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / SMC21LIB.LZH / ITOX.C < prev    next >
Text File  |  2000-06-30  |  640b  |  27 lines

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