# Unfamiliar Syntax "int x = i1 << 24 | i2 ..."

• 04-09-2009, 04:43 PM
KentDMc
Unfamiliar Syntax "int x = i1 << 24 | i2 ..."
Hi folks,

I'm coming accross a syntax I'm not familiar with and am unable to Google it because of the characters involved...

Here is an example.

Code:

```int i1, i2, i3, i4; //set the ints to some values int x = i1 << 24 | i2 << 16 | i3 << 8 | i4;```
I don't understand what that last line is doing. Can anyone explain this?
• 04-09-2009, 04:51 PM
Eranga
In your expression you have three operators, =, << and |. I guess did you know the meaning of each of these.
• 04-09-2009, 05:28 PM
xcallmejudasx
i believe the << is a bit operator meaning shift left and the | works the same as || but for bit manipulation.
• 04-09-2009, 06:30 PM
xcallmejudasx
I was correct. Read up here Bitwise and Bit Shift Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

the << is the Signed left shift and the | is a bitwise inclusive or. the following truth table explains how your 4 parameters would end up true

p1|p2|p3|p4|'|'|
0 | 0| 0 | 1 |1
0 | 0| 1 | 0 |1
0 | 1| 0 | 0 |1
1 | 0| 0 | 0 |1

any other combination will return false unless you place parentheses around your operators.
• 04-10-2009, 03:23 PM
KentDMc
SOLVED - Thanks
Thank you for your responses, guys. When I first looked at this I thought it was some kinda of logical shortcut, similar to max = (a > b) ? a : b;
• 04-11-2009, 03:21 AM
Eranga
Actually this is about ternary operator, simplest form of if-else condition. Logical operators are totally different from this.