获取某位的值,从低位到高位(右到左)

// test.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;

int ok(int n,int _Mask)  
{  
	_Mask = _Mask -1;
	int a=1;
	a<<=_Mask;
	n&=a;
	if(n == a)
	{
		return 1;
	}
	return 0;
}  

int _tmain(int argc, _TCHAR* argv[])	
{
	cout << ok(3,3);
	cout << ok(3,2);
	cout << ok(3,1);
	cout<<endl;
	system("pause");
	return 0;
}


相关文章:

  • 2022-02-07
  • 2022-12-23
  • 2021-08-16
  • 2021-06-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-14
  • 2021-12-03
  • 2021-07-12
  • 2021-07-25
  • 2021-08-07
  • 2021-05-19
相关资源
相似解决方案