VC 6.0中char a(1)输出是个笑脸

sankunpt1 2011-07-13 08:11:27
先贴上代码,直接输出的时候就是个笑脸,转换成二进制数出就是正常的00000001,不知道怎么回事呢?

#include <iostream>
#include <string.h>
using namespace std;

void binary_print(char c)
{
for(int i = 0; i < 8; ++i)
{
if(c << i & 0x80)
cout << '1';
else
cout << '0';
}
cout << ' ';
}

int main()
{
string str("Hello world");
int someval(1),someotherval(1);
str[someotherval*someval]=someval;
cout<<str[someotherval*someval]<<endl;
char a(1);
binary_print(a);

return 0;
}
...全文
306 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ouwarmth 2011-07-13
  • 打赏
  • 举报
回复
char a(1);char类型占1个字节,总共有8个位。把a作为参数传入,通过下面的移位运算:可以得到00000001。
void binary_print(char c)
{
for(int i = 0; i < 8; ++i)
{
if(c << i & 0x80)
cout << '1';
else
cout << '0';
}
cout << ' ';
}
W170532934 2011-07-13
  • 打赏
  • 举报
回复
由于asc为1是不可打印的字符,所以windows处理了下。
pathuang68 2011-07-13
  • 打赏
  • 举报
回复
我们知道 printf("\1"); 的作用是打印出ASCII码为1的字符。
查询ASCII码表中,十进制的1对应的ASCII意思是soh,即start of head,标题开头的意思。
该符号为通信专用字符,如果只是用作显示,系统会使用一个特定的图形来显示,这就是我们看到的笑脸。
sankunpt1 2011-07-13
  • 打赏
  • 举报
回复
部分代码来自C++ primer

64,685

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧