#include <stdio.h>
int main()
{
int num;
int i, j;
char arr1[16];
char arr2[16];
printf("input a num:");
scanf_s("%d", &num);
for (i = 0,j=0; i < 32; i += 2,j++)
{
arr1[15-j] = (num >> i) & 1; //利用移位运算符
}
printf("num的二进制数的奇数序列为:");
for (j = 0; j < 16; j++)
{
printf("%d ", arr1[j]);
}
printf("\n");
for (i = 1, j = 0; i < 32; i += 2, j++)
{
arr2[15 - j] = (num >> i) & 1;
}
printf("num的二进制数的偶数序列为:");
for (j = 0; j < 16; j++)
{
printf("%d ", arr2[j]);
}
return 0;
}
int main()
{
int num;
int i, j;
char arr1[16];
char arr2[16];
printf("input a num:");
scanf_s("%d", &num);
for (i = 0,j=0; i < 32; i += 2,j++)
{
arr1[15-j] = (num >> i) & 1; //利用移位运算符
}
printf("num的二进制数的奇数序列为:");
for (j = 0; j < 16; j++)
{
printf("%d ", arr1[j]);
}
printf("\n");
for (i = 1, j = 0; i < 32; i += 2, j++)
{
arr2[15 - j] = (num >> i) & 1;
}
printf("num的二进制数的偶数序列为:");
for (j = 0; j < 16; j++)
{
printf("%d ", arr2[j]);
}
return 0;
}