#include <iostream>
#include<bitset>
using namespace std;
int main()
{
int a=100;int 一般占4字节
cout<<bitset<sizeof(a)*8>(a)<<endl;8表示一个字节占的位数,可以改变
short aa=100;
int bb=100;
long cc=100;
long long dd=100;
cout<<bitset<sizeof(aa)*8>(aa)<<endl;
cout<<bitset<sizeof(bb)*8>(bb)<<endl;
cout<<bitset<sizeof(cc)*8>(cc)<<endl;
cout<<bitset<sizeof(dd)*8>(dd)<<endl;
cout<<endl;
double ee=2.05;
float ff=2.05;
long double gg=2.05;
cout<<bitset<sizeof(ee)*8>(ee)<<endl;
cout<<bitset<sizeof(ff)*8>(ff)<<endl;
cout<<bitset<sizeof(gg)*8>(gg)<<endl;
cout<<endl;
bool b1=0;bool b2=1;bool b3='h';bool b4=' ';bool b5;
cout<<bitset<sizeof(b1)*8>(b1)<<endl;
cout<<bitset<sizeof(b2)*8>(b2)<<endl;
cout<<bitset<sizeof(b3)*8>(b3)<<endl;
cout<<bitset<sizeof(b4)*8>(b4)<<endl;
cout<<bitset<sizeof(b5)*8>(b5)<<endl;
return 0;
}
00000000000000000000000001100100
0000000001100100
00000000000000000000000001100100
00000000000000000000000001100100
0000000000000000000000000000000000000000000000000000000001100100
0000000000000000000000000000000000000000000000000000000000000010
00000000000000000000000000000010
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010
00000000
00000001
00000001
00000001
00000000
可以说明该系统or该编译器下每种数据类型占的字节数是多少.
#include <iostream>
#include<bitset>
using namespace std;
int main()
{
int a=100;int 一般占4字节
cout<<bitset<sizeof(a)*8>(a)<<endl;
int a1=200;
cout<<oct<<a1<<endl;//310---octagon八边形
cout<<hex<<a1<<endl;//c8----hexadecimal十六进制
cout<<dec<<a1<<endl;//200---decade,deca,decadal
int x,y;
cout<<"_______________input x(oct)"<<endl;
cin>>oct>>x;//如果输出数字>=8的话,编译就会快速结束0000....
cout<<"_______________the result is---"<<endl;
cout<<"x: "<<x<<endl;
cout<<"_______________the result is--(oct)+(hex)---"<<endl;
cout<<oct<<x<<endl;
cout<<hex<<x<<endl;
cout<<"_______________input y(hex)"<<endl;
cin>>hex>>y;//[输入方式]继承上面y的hex;
cout<<"_______________input x"<<endl;
cin>>x;
cout<<"_______________the result is---"<<endl;
cout<<"x: "<<x<<"\ty: "<<y<<endl;//[输出方式]继承上面的hex;
cout<<"_______________the result is--(oct-x,y)+(hex-x,y)---"<<endl;
cout<<"oct-x:"<<oct<<x<<endl;
cout<<"oct-y:"<<oct<<y<<endl;
cout<<"hex-x:"<<hex<<x<<endl;
cout<<"hex-y:"<<hex<<y<<endl;
cout<<"*****next turn*****"<<endl;
cout<<"_______________input x(oct)"<<endl;
cin>>oct>>x;
cout<<"_______________the result is---"<<endl;
cout<<"x: "<<x<<endl;
cout<<"_______________the result is--(hex)+(oct)---"<<endl;
cout<<hex<<x<<endl;
cout<<oct<<x<<endl;
cout<<"_______________input y(hex)"<<endl;
cin>>hex>>y;
cout<<"_______________input x"<<endl;
cin>>x;//[输入方式]继承上面y的hex;
cout<<"_______________the result is---"<<endl;
cout<<"x: "<<x<<"\ty: "<<y<<endl;//[输出方式]继承上面的oct;
cout<<"_______________the result is--(oct-x,y)+(hex-x,y)---"<<endl;
cout<<"oct-x:"<<oct<<x<<endl;
cout<<"oct-y:"<<oct<<y<<endl;
cout<<"hex-x:"<<hex<<x<<endl;
cout<<"hex-y:"<<hex<<y<<endl;
return 0;
}
00000000000000000000000001100100
310
c8
200
_______________input x(oct)
6677
_______________the result is—
x: 3519
_______________the result is–(oct)+(hex)—
6677
dbf
_______________input y(hex)
5577
_______________input x
4477
_______________the result is—
x: 4477 y: 5577
_______________the result is–(oct-x,y)+(hex-x,y)—
oct-x:42167
oct-y:52567
hex-x:4477
hex-y:5577
***** next turn *****
_______________input x(oct)
6677
_______________the result is—
x: dbf
_______________the result is–(hex)+(oct)—
dbf
6677
_______________input y(hex)
5577
_______________input x
4477
_______________the result is—
x: 42167 y: 52567
_______________the result is–(oct-x,y)+(hex-x,y)—
oct-x:42167
oct-y:52567
hex-x:4477
hex-y:5577
可以看出,每一次对cin设置输出进制类型后,这个状态会一直保持;
每一次对cout设置也是如此.