-4

I want to known a simple thing. I have this part of code:

int datam=2;
for (int j=0; j<4; j++){
  cout<<((datam >> j)&1); 
}

What does it print this code? Does it do the AND bit to bit between 1 and datam>>j? As operator, what's the meaning of datam >> j? Thanks.

Local Hero
  • 493
  • 2
  • 7
  • 20
  • 2
    Have you read the [manual](http://en.cppreference.com/w/cpp/language/operator_arithmetic) first? – axiac Jul 07 '15 at 10:01
  • 1
    Valid question, even in software engineering classes they say that `>>` is stream operator not even mentioning about bit shifts. It does not mean however that google wouldn't know. – riodoro1 Jul 07 '15 at 10:06
  • 2
    @riodoro1 Have you ever tried searching for punctuation? Try typing `>>` into Google. – David Heffernan Jul 07 '15 at 10:09

1 Answers1

1
  • When passed two int operants, & is the bitwise AND operator.
  • When passed two int operands, >> is the bitwise right shift operator.

You can learn more details from any good text book, or online reference. For instance: http://en.cppreference.com/w/cpp/language/operator_arithmetic

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490