简体   繁体   中英

C - how do I convert char(8-bit) to ascii format

I wonder how to convert like a char: 1101_0110(D6) to two char(ascii format) 0100_0100(44) and 0011_0110(36). Thanks a lot!

sample code

#include <stdio.h>

int main(void){
    char x = '\xD6';
    char asc[3];
    sprintf(asc, "%02X", (unsigned char)x);
    printf("%s\n", asc);//D6
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM