请教一个非常傻的C++问题
来源:百度知道 编辑:UC知道 时间:2024/07/08 01:24:31
首先声明我是个大菜鸟! 给定一个字符变量输出其二进制形式。例如char a=’a’; 其二进制为00100001。
这个程序怎么写?是给定的字符变量哦!
用C++的形式,不要C的
这个程序怎么写?是给定的字符变量哦!
用C++的形式,不要C的
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
char a='a';
cout<<bitset<sizeof(char)*8>(a)<<endl;
}
http://hi.baidu.com/zhangshourui/blog/item/32e9e2dddae008e677c638b3.html
调用方法
char a = 'a';
char* outBuf = NULL;
int len = 0;
int nRet = dumpMem(&a, sizeof(a), NULL, &len);
if(1==nRet)
{
outBuf = new char[len];
nRet = dumpMem(&a, sizeof(a), outBuf, &len);
assert(nRet==0);
cout<<outBuf<<endl;
cout<<nRet<<" bytes returned"<<endl;
}
delete outBuf;
#include <iostream>
#include <cmath>
using namespace std;
void tentotwo(int ten)
{
int two = 0;
int count = 0;
while(ten != 0