|| is binary OR operation. The operations takes the two values on either side and merges them to create the answer. The merge occurs at bit level.
<< Shift Bits Left operation. For each shift left, we're multing the value by 2.
The original code is packing the four key states into a single value. So it reads each key state, which gives a 0 or 1 (On or Off) answer. It then is shifts (mults) the answers and by a power of 2. So each answer is represented by a single bit in the output.
To remove the OR and SHIFTS..
Original code,
flags = (upkey() || downkey() << 1 || leftkey() << 2 || rightkey() << 3)
Replace OR's with additions. This is viable since none of the shifted state bits overlap, if they didn, it wouldn't work.
Now: We've assuming here that SHIFT has precedence over ADDITION, so to avoid any unwanted behavior we stick some () around the calc's, just to be sure.
flags = upkey() + (downkey() << 1) + (leftkey() << 2) + (rightkey() << 3)
We can use Mults in place of the shifts. For each bit a value is shifted left is like multiplying by 2. So if we shift it 2 bits, thats like ((Value*2)*2) or Value*4. If we shift 3 bits left it's (((value*2)*2)*2) or Value *8.
flags = upkey() + (downkey() *2) + (leftkey() *4) + (rightkey() *8)
This creates a 4 bit packed value of the 4 key states. This gives us 16 possible input combinations.
-----------------------------------------
Decimal / Binary / Keys Down
-----------------------------------------
00 =%0000 = No keys are pressed
01 =%0001 = UpKey
02 =%0010 = DownKey
03 =%0011 = DownKey + UpKey
04 =%0100 = LeftKey
05 =%0101 = LeftKey +UpKey
06 =%0110 = LeftKey +DownKey
07 =%0111 = LeftKey +DownKey+ UpKey
08 =%1000 = RightKey
09 =%1001 = RightKey + UpKey
10 =%1010 = RightKey + DownKey
11 =%1011 = RightKey + DownKey + UpKey
12 =%1100 = RightKey + LeftKey
13 =%1101 = RightKey + LeftKey +UpKey
14 =%1110 = RightKey + LeftKey +DownKey
15 =%1111 = RightKey + LeftKey +DownKey+ UpKey