Jordan Jordan - 1 year ago 131
C Question

Convert from a binary to char in C

I'm flummoxed by how to convert from a binary value to a char in c.

For example, let's say I have 01010110 and want to print the corresponding letter 'V' from that. How do I do this?

Thanks for any help!

Answer Source
#include <stdio.h>
#include <stdlib.h>
int main(void)
    char *data = "01010110";
    char c = strtol(data, 0, 2);
    printf("%s = %c = %d = 0x%.2X\n", data, c, c, c);


01010110 = V = 86 = 0x56


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download