操作符
~(_:)
返回参数中设置的位的倒数。
声明
static func ~ (x: Self) -> Self
详述
按位非运算符 (~
) 是一个前缀运算符,它返回一个值,在该值中其参数的所有位都被翻转:参数中为 1
的位在结果中为 0
;并且参数中为0
的位在结果中为1
。这相当于集合的逆。例如:
let x: UInt8 = 5 // 0b00000101
let notX = ~x // 0b11111010
对 0 执行按位非运算会返回一个值,每个位都设置为 1
。
let allOnes = ~UInt8.min // 0b11111111
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相关用法
- Swift Int >>=(_:_:)用法及代码示例
- Swift Int &>>=(_:_:)用法及代码示例
- Swift Int *=(_:_:)用法及代码示例
- Swift Int ^(_:_:)用法及代码示例
- Swift Int &-(_:_:)用法及代码示例
- Swift Int init(exactly:)用法及代码示例
- Swift Int |(_:_:)用法及代码示例
- Swift Int &=(_:_:)用法及代码示例
- Swift Int <<(_:_:)用法及代码示例
- Swift Int +(_:)用法及代码示例
- Swift Int >>(_:_:)用法及代码示例
- Swift Int ..<(_:)用法及代码示例
- Swift Int /=(_:_:)用法及代码示例
- Swift Int multipliedFullWidth(by:)用法及代码示例
- Swift Int -(_:_:)用法及代码示例
- Swift Int ...(_:_:)用法及代码示例
- Swift Int &*=(_:_:)用法及代码示例
- Swift Int &(_:_:)用法及代码示例
- Swift Int /(_:_:)用法及代码示例
- Swift Int ...(_:)用法及代码示例
- Swift Int init(clamping:)用法及代码示例
- Swift Int ..<(_:_:)用法及代码示例
- Swift Int init(truncatingIfNeeded:)用法及代码示例
- Swift Int &*(_:_:)用法及代码示例
- Swift Int random(in:using:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 Int ~(_:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。