实例十一:取n的某些位

方法:result=(n>>4)&(~(~0<<4))

取出某数n的低4位。

 

数值0         0000 0000
~0           1111 1111
~0<<4          1111 0000
~(~0<<4)      0000 1111


int _tmain(int argc, _TCHAR* argv[])
{
  int n,m,nResult = 0;

  cout << "请输入原始的值:";
  cin >> n;

  m = n >> 4;

  nResult = m &(~(~0<<4));

  cout << endl << nResult;

  system("pause");
  return 0;
};

相关文章:

  • 2021-06-23
  • 2022-12-23
  • 2021-11-22
  • 2021-09-05
  • 2022-12-23
  • 2021-11-14
  • 2022-02-10
  • 2021-06-24
猜你喜欢
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2021-11-05
  • 2021-09-20
  • 2022-12-23
相关资源
相似解决方案