Get all the even and odd bits in an integer binary sequence, and print out the binary sequence respectively.
For example:
The binary sequence of 1 is: 00000000000000000000000000000001,
then the printed out should be:
Odd digits: 0000000000000001
Even digits: 0000000000000000 The
code is as follows:
#include<stdio.h>
void print(int m)
{
int i=0;
printf("奇数位:\n");
for(i=30;i>=0;i-=2)
{
printf("%d",(m>>i)&1);
}
printf("\n");
printf("偶数位:\n");
for(i=31;i>=1;i-=2)
{
printf("%d",(m>>i)&1);
}
printf("\n");
}
int main()
{
int m=0;
scanf("%d",&m);
print(m);
return 0;
}
The result of the operation is shown in the figure:
Caicai's code, I hope it can help you!