C language-Get all the even and odd bits in a binary sequence of numbers, and output the binary sequence respectively.

Title description: Get all the even and odd bits in a binary sequence of numbers, and output the binary sequence respectively.

   二进制数:00000000 00000000 00000000 00011001       //25
   偶数序列:0000000000000010
   奇数序列:0000000000000101

Thinking Answer: bits and (&) operation by pressing the search violence get every

Are there any other concise ideas to share

#include<stdio.h>

int main()
{
    
    
    int value = 0;
    scanf("%d", &value); 
    
    printf("偶数序列>");
    for (int i = 31; i >= 1; i -= 2)
    {
    
    
        printf("%d", (value >> i) & 1);
    }
    printf("\n");

    printf("奇数序列>");
    for (int j = 30; j >= 0; j -= 2)
    {
    
    
        printf("%d", (value >> j) & 1);
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/and_what_not/article/details/113764194