试题名称 算法提高 输出二进制表示 语言 C++

利用 n与0000 0001和 0000 0010到1000 0000

求&(与)运算 得出n化为二进制的状态  <<指向左移位运算 >>同理

代码 已过AC

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
main()
{
    int n,i=1,a[8];
    memset(a,0,sizeof(a));
    scanf("%d",&n);
    if(n&1)
    a[0]=1;
    for(;i<8;i++)
    {
        if(n&2<<(i-1))
        {
            a[i]=1;
            continue;
        }
    }
    for(int j=7;j>=0;j--)
    {
        cout<<a[j];
    }
}

相关文章:

  • 2022-02-08
  • 2022-12-23
  • 2021-11-30
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-03
  • 2021-11-30
  • 2021-07-08
  • 2021-10-18
  • 2021-11-21
  • 2021-08-23
  • 2021-04-04
相关资源
相似解决方案