C# Left Shift Operator

前端 未结 4 570
梦如初夏
梦如初夏 2021-01-14 01:47

There\'s a statement a co-worker of mine wrote which I don\'t completely understand. Unfortunately he\'s not available right now, so here it is (with modified names, we\'re

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-14 02:18

    The code is shifting the binary value 1 to the left, the number of binary places to shift is determined by the Apple and Banana, after both values are shifted the are ORed in a binary way

    Example: Assume apple returns 2 and banana returns 3 you get: 1 << 2 which is 0100 (that means 4 in decimal) 1 << 3 which is 1000 ( that means eight in decimal)

    now 0100 bitwise or with 1000 is 1100 which means 12

提交回复
热议问题