【CSAPP】第三章练习题3.26调试程序

#include <iostream>

using namespace std;

void bin(int n)
{
    int res = 0;
    for (int i = 3; i >= 0; i -- )
        cout << (n >> i & 1);
}

long fun_a(unsigned long x)
{
    long val = 0;
    while (x)
    {
        cout << "val = " << val << "  x = " << x << endl;
        cout << "val ^= x之后" << endl;
        val ^= x;
        cout << "val: " << val << "   二进制:";
        bin(val); cout << endl;
        x >>= 1;
        cout << "x: " << x << endl;
        cout << "---------" << endl;
    }
    return val & 0x1;
}

int main()
{
    cout << fun_a(10) << endl;
    return 0;
}
posted @ 2022-12-08 17:56  Tshaxz  阅读(93)  评论(0编辑  收藏  举报
Language: HTML