输入一个英文字符用二进制输出ASCII码
和大家一起分享哦~~~~~~~~~#include <stdio.h>
void main()
{
char b,c,b1,b2,b3,b4,b5,b6,b7,b8;
printf("输入一个字符:");
b=getchar();
c=b;
b8=b%2;b=b/2;
b7=b%2;b=b/2;
b6=b%2;b=b/2;
b5=b%2;b=b/2;
b4=b%2;b=b/2;
b3=b%2;b=b/2;
b2=b%2;b=b/2;
b1=b%2;b=b/2;
b1=b%2;
printf("%c的二进制ASCII码是:%d%d%d%d%d%d%d%d\n",c,b1,b2,b3,b4,b5,b6,b7,b8);
}
----------------解决方案--------------------------------------------------------
你写的太复杂了
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main()
{
char ch;
char str[32];
int tmp;
printf("Enter a char:");
ch=getchar();
printf("The binary value of ASCII is:%s",itoa(ch,str,2));
getch();
return 0;
}
----------------解决方案--------------------------------------------------------
2楼的用itoa简单些
----------------解决方案--------------------------------------------------------
大家不用库函数实现还有更好的方法吗?
----------------解决方案--------------------------------------------------------
哦,谢谢呢!!!
----------------解决方案--------------------------------------------------------