十进制转16进制 、十进制转二进制 函数

                                      

include "string.h"
include
"stdio.h"
char *dectohex(int dec, int len
)
{
 
static char buf[256
];
 
char cell[] = "0123456789ABCDEF"
;
 
int i = 0
;
 
memset(buf, 0, 256
);
 
memset(buf, '0', len
);
 
while (dec != 0
)
  {
   
buf[i++] = cell[dec % 16
];
   
dec = dec / 16
;
  }
 
strcat(buf, "x0"
);
 
return (strrev(buf
));
}
char *dectobin(int dec, int len
)
{
 
int i = 0
;
 
static char buf[256
];
 
memset(buf, 0, 256
);
 
memset(buf, '0', len
);
 
while (dec != 0
)
  {
   
buf[i++] = dec % 2+48
;
   
dec = dec / 2
;
  }
 
return strrev(buf
);
}

相关文章:

  • 2022-12-23
  • 2021-08-22
  • 2021-12-04
  • 2021-04-13
  • 2022-01-24
  • 2022-12-23
猜你喜欢
  • 2022-01-09
  • 2021-08-11
  • 2022-12-23
  • 2021-09-14
  • 2021-04-28
  • 2021-05-24
  • 2021-05-12
相关资源
相似解决方案