What do the & and | operators do? How are they different from && and ||? Swift

后端 未结 3 1874
故里飘歌
故里飘歌 2021-01-24 12:38

I\'ve seen many instances where | or &are used, but I haven\'t understood what they are used for. I know what && and ||<

3条回答
  •  猫巷女王i
    2021-01-24 12:52

    You can read about them and their differences in Swift docs.

    Logical Operators 1

    Logical operators modify or combine the Boolean logic values true and false. Swift supports the three standard logical operators found in C-based languages:

    Logical NOT (!a)
    
    Logical AND (a && b)
    
    Logical OR (a || b)
    

     

    Bitwise Operators 2

    Bitwise operators enable you to manipulate the individual raw data bits within a data structure. They are often used in low-level programming, such as graphics programming and device driver creation. Bitwise operators can also be useful when you work with raw data from external sources, such as encoding and decoding data for communication over a custom protocol.

    Swift supports all of the bitwise operators found in C, as described below.

提交回复
热议问题