solution.cpp 306 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <stdio.h>

void f(int x)
{
    int i;
    for (i = 0; i < 32; i++)
        printf("%d", (x >> (31 - i)) & 1);
    printf("   ");

    x = x & (x + 1);

    for (i = 0; i < 32; i++)
        printf("%d", (x >> (31 - i)) & 1);
    printf("\n");
}

int main()
{
    f(103);
    f(12);
    return 0;
}