问一个问题阿!快来帮帮我阿,谢了各位兄弟!!

Rayphrank 2003-04-10 11:27:32
字符的位表示怎样转换成字符串阿?
比如"A"十六进制为41,二进制为01000001,我的问题是怎样在输入"A"后转换成
字符串“01000001”,其它字符类推
最好有源代码,谢了各位!!
...全文
84 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fangrk 2003-04-11
  • 打赏
  • 举报
回复
#include <string>
#include <iostream>
#include <bitset>
using namespace std;

int main()
{
bitset<8> bitStr;
bitStr|=static_cast<int>('A');
string binaryStr(bitStr.template to_string<char,char_traits<char>,allocator<char> >());
cout<<binaryStr;
}
kaitty 2003-04-11
  • 打赏
  • 举报
回复
这样就可以了

#include <string>
#include <iostream>
#include <bitset>

using namespace std;

int main()
{
bitset<8> bitStr;
bitStr|=static_cast<int>('A');
string binaryStr(bitStr.to_string() );
cout<<binaryStr;

return 0;
}
kaitty 2003-04-11
  • 打赏
  • 举报
回复
伙计,你的程序编译通不过啊?
  • 打赏
  • 举报
回复
将一个字符转换为二进制数

#include <cstdlib>
#include <stdio.h>
int main(){
char buffer[10];
char a='A';
_itoa(a,buffer,2);
printf("%s",buffer);
return 0;
}

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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