topxebec
topxebec

Reputation: 1427

What does 'int kk = 2 | 3;' mean?

I have been programming in java for a while but I have not met a strange expression

int kk = 2 | 3;

What does '|' mean in this expression? It seems hard to Google it.

I met it in source

i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

Why we need to use this?

Upvotes: 3

Views: 288

Answers (4)

Raveesh Sharma
Raveesh Sharma

Reputation: 1486

You can have a look at http://vipan.com/htdocs/bitwisehelp.html I think they are really very good tutorials on bit shift operators

Upvotes: 1

Jay
Jay

Reputation: 24905

| is a bitwise Operator. In your case, 2|3 will produce 3 as 2 is 10 and 3 is 11. 10 | 11 = 11.

Upvotes: 2

MRalwasser
MRalwasser

Reputation: 15973

It's the "bitwise inclusive or operator".

Upvotes: 4

Michael Borgwardt
Michael Borgwardt

Reputation: 346476

It's a bitwise or - each result bit will be set if either or both inputs have a bit set in that position. 2 is 10 in binary, 3 is 11, so the result will also be 3.

Upvotes: 8

Related Questions