c++ 64位二进制 移位运算并输出结果

来源:互联网 发布:淘宝上的win10激活码 编辑:程序博客网 时间:2024/05/16 07:07

一个很一般的程序


#include<iostream>
using namespace std;
void main(){
int a,b,p;
cout<<"entre a,b:"<<endl;
cin>>hex>>a>>b;
cout<<"a=";
cout.width(8); //宽度是8
cout.fill('0');//前面补0
cout <<hex << a<<endl;
cout<<"b=";
cout << hex << b<<endl;
p=b&0X80000000;

//cout << hex << p<<endl;
//cout << dec << p<< endl;
//cout<<p<<endl;
cout<<"after left shift a b=";
if(p==0){
a=a<<1;
b=b<<1;
    cout.width(8);
    cout.fill('0');
        cout<<a<<" ";

cout<<b<<endl;
}
else{
a=a<<1;
a=a|1;
b=b<<1;
        cout.width(8);
    cout.fill('0');
        cout<<a<<" ";
cout<<b<<endl;
}




}

0 0