monta yen
monta yen

Reputation: 15

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!

Upvotes: 0

Views: 449

Answers (1)

BLUEPIXY
BLUEPIXY

Reputation: 40145

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
}

Upvotes: 3

Related Questions