Syntax in Java math operations (bitwise or equals)

前端 未结 2 1910
你的背包
你的背包 2021-01-24 14:58

Google doesn\'t seem to help with the following: in Java, what does the following mean?

long_num1 |= long_num2
相关标签:
2条回答
  • 2021-01-24 15:26

    Means long_num1 = long_num1 | long_num2.

    The | is bitwise OR.

    0 讨论(0)
  • 2021-01-24 15:35

    It's a bitwise OR logical operation.

    1 | 0 = 1
    1001 | 0101 = 1101
    11110000 | 00001111 = 11111111
    

    It's commonly used when one has to deal with bit fields. The long_num values store multiple Boolean flags as individual bits of the whole integer.

    Note however that Java has a built-in feature for dealing with bit fields: the BitSet class.

    0 讨论(0)
提交回复
热议问题