0

this is very simple code but i don't understand why this happeded. here is my code.

#include <iostream>

using namespace std;

int main()
{
    for(int i = 0; i < 32; i++)
    {
    int tmp = i;
    if(tmp & 1 == 0)
        cout << '0' << endl;
    else
        cout << '1' << endl;
    }

    return 0;
}

i was expect that output will be "0101..." but real output was "1111..."

however when i changed condition code like

if(tmp & 1 == 1)

the code work right which i expected. is someone able to answer me why this two code makes different output?

신승빈
  • 347
  • 3
  • 10

0 Answers0