home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / misc / smc203.ark / ITOX.C < prev    next >
Encoding:
Text File  |  1983-07-28  |  640 b   |  24 lines

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