-6
int flags = 22 | 225 | 222;

what is this code i don't understand what's happens>>

Shahriyar
  • 23
  • 6
  • What you mean by "what is this code" ? – hellzone Apr 17 '18 at 11:42
  • 3
    Possible duplicate of [How Does The Bitwise & (AND) Work In Java?](https://stackoverflow.com/questions/17256644/how-does-the-bitwise-and-work-in-java) – Joe Apr 17 '18 at 11:42
  • "what is this code" - bizarre way of setting it to 255, if they are literal values this looks more like deliberate (but poor) obfuscation of some kind. – Andrew Apr 17 '18 at 11:47
  • 2
    This bit-wise OR-ing looks **suspicious**. Maybe originally it was in **base 8**: `022 | 0225 | 0222` for Unix user/group/others rights or such. – Joop Eggen Apr 17 '18 at 11:49

2 Answers2

4
22,  in binary 0000000000010110
225, in binary 0000000011100001
222, in binary 0000000011011110

| is binary OR operator:

The binary OR operation has two inputs and one output. It is like the ADD operation which takes two arguments (two inputs) and produces one result (one output).

A B C

0 OR 0 -> 0

0 OR 1 -> 1

1 OR 0 -> 1

1 OR 1 -> 1

0000000000010110 | 0000000011100001| 0000000011011110 = 0000000011111111 (in decimal 255)
xingbin
  • 27,410
  • 9
  • 53
  • 103
-1

| is Bitwise Operators so here you added 22 + 225 + 222 in binary way

Elarbi Mohamed Aymen
  • 1,617
  • 2
  • 14
  • 26