在C中从二进制转换为char [英] Convert from a binary to char in C
本文介绍了在C中从二进制转换为char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对如何从二进制值转换为c中的char感到困惑.
I'm flummoxed by how to convert from a binary value to a char in c.
例如,假设我有01010110,并希望从中打印相应的字母"V".我该怎么做呢?
For example, let's say I have 01010110 and want to print the corresponding letter 'V' from that. How do I do this?
感谢您的帮助!
推荐答案
#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);
return(0);
}
输出:
01010110 = V = 86 = 0x56
参考:
这篇关于在C中从二进制转换为char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文