不用非标准库函数,自己随手写一个转换函数:
#include <stdio.h> void convert(unsigned char c, unsigned char* out){ for(int i=0; i<8; i++) { *(out+i) = (c & (0x80 >> i))==0 ? 0x30 : 0x31; } } int main() { unsigned char buf[9] = {0}; long long int a = 0x0123456789abcdef; unsigned char* p = (unsigned char*)&a; for(int i=0; i<sizeof(a); i++){ convert(*(p+i), buf); printf("%s ", buf); } return 0; }