#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;
int youyi(int x,double n)
{
double l = sizeof(int)*8;
int r;
r = ( x&( (int)pow(2,(l-n))-1 ) ) * ((int)pow(2,n));
return r;
}
int _tmain(int argc, _TCHAR* argv[])
{
cout<<youyi(1,2)<<endl;
system("pause");
return 0;
}
#include <iostream>
#include <math.h>
using namespace std;
int youyi(int x,double n)
{
double l = sizeof(int)*8;
int r;
r = ( x&( (int)pow(2,(l-n))-1 ) ) * ((int)pow(2,n));
return r;
}
int _tmain(int argc, _TCHAR* argv[])
{
cout<<youyi(1,2)<<endl;
system("pause");
return 0;
}
本文详细介绍了C++中位运算符的使用方法及常见位操作技巧,包括位与、位或、位异或、位取反等,并通过实例展示了如何在实际编程中灵活运用这些操作。
393

被折叠的 条评论
为什么被折叠?



