就是移位操作啦
16->2
```
#include "stdio.h"
int main(void)
{
int n;
int d=1;
char src[1024]={0};
int len=0,i=0;
scanf("%x",&n);
sprintf(src,"%x",n);
len=strlen(src);
for(i=len*4-1;i>=0;--i)
printf("%d",(n & (d<<i))>>(i));
printf("\n%s\n",src);
return 0;
}
```
10->2
```
#include "stdio.h"
int main(void)
{
int n;
int d=1;
char src[1024]={0};
int len=0,i=0;
scanf("%d",&n);
sprintf(src,"%d",n);
len=strlen(src);
for(i=len*4-1;i>=0;--i)
printf("%d",(n & (d<>(i));
printf("\n%s\n",src);
return 0;
}
```
网友评论