用法一
操作符
&>>=(_:
&>>=(_:_:)
計算將值的二進製表示向右移動指定位數的結果,將移位量屏蔽為類型的位寬,並將結果存儲在左側變量中。
必需的。提供默認實現。
聲明
static func &>>= (lhs: inout Self, rhs: Self)
參數
lhs
要轉移的值。
rhs
向右移動
lhs
的位數。如果rhs
超出範圍0..<lhs.bitWidth
,則會對其進行屏蔽以生成該範圍內的值。
詳述
&>>=
運算符執行 masking shift
,其中作為 rhs
傳遞的值被屏蔽以產生 0..<lhs.bitWidth
範圍內的值。使用此屏蔽值執行移位。
以下示例將 x
定義為 UInt8
的一個實例,這是一個 8 位無符號整數類型。如果在對 x
的操作中使用 2
作為右側值,則移位量不需要屏蔽。
var x: UInt8 = 30 // 0b00011110
x &>>= 2
// x == 7 // 0b00000111
但是,如果您將 19
用作 rhs
,則操作首先將 rhs
位掩碼到 3
,然後使用該掩碼值作為要移位的位數 lhs
。
var y: UInt8 = 30 // 0b00011110
y &>>= 19
// y == 3 // 0b00000011
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
用法二
操作符
&>>=(_:
&>>=(_:_:)
計算將值的二進製表示向右移動指定位數的結果,將移位量屏蔽為類型的位寬,並將結果存儲在左側變量中。
聲明
static func &>>= <Other>(lhs: inout Self, rhs: Other) where Other : BinaryInteger
參數
lhs
要轉移的值。
rhs
向右移動
lhs
的位數。如果rhs
超出範圍0..<lhs.bitWidth
,則會對其進行屏蔽以生成該範圍內的值。
詳述
&>>=
運算符執行 masking shift
,其中作為 rhs
傳遞的值被屏蔽以產生 0..<lhs.bitWidth
範圍內的值。使用此屏蔽值執行移位。
以下示例將 x
定義為 UInt8
的一個實例,這是一個 8 位無符號整數類型。如果在對 x
的操作中使用 2
作為右側值,則移位量不需要屏蔽。
var x: UInt8 = 30 // 0b00011110
x &>>= 2
// x == 7 // 0b00000111
但是,如果您將 19
用作 rhs
,則操作首先將 rhs
位掩碼到 3
,然後使用該掩碼值作為要移位的位數 lhs
。
var y: UInt8 = 30 // 0b00011110
y &>>= 19
// y == 3 // 0b00000011
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相關用法
- Swift FixedWidthInteger &>>(_:_:)用法及代碼示例
- Swift FixedWidthInteger &-=(_:_:)用法及代碼示例
- Swift FixedWidthInteger &<<=(_:_:)用法及代碼示例
- Swift FixedWidthInteger &<<(_:_:)用法及代碼示例
- Swift FixedWidthInteger &-(_:_:)用法及代碼示例
- Swift FixedWidthInteger &*=(_:_:)用法及代碼示例
- Swift FixedWidthInteger &+=(_:_:)用法及代碼示例
- Swift FixedWidthInteger &*(_:_:)用法及代碼示例
- Swift FixedWidthInteger &+(_:_:)用法及代碼示例
- Swift FixedWidthInteger multipliedFullWidth(by:)用法及代碼示例
- Swift FixedWidthInteger nonzeroBitCount用法及代碼示例
- Swift FixedWidthInteger init(_:radix:)用法及代碼示例
- Swift FixedWidthInteger random(in:)用法及代碼示例
- Swift FixedWidthInteger dividingFullWidth(_:)用法及代碼示例
- Swift FixedWidthInteger leadingZeroBitCount用法及代碼示例
- Swift FixedWidthInteger random(in:using:)用法及代碼示例
- Swift FixedWidthInteger用法及代碼示例
- Swift FlattenSequence prefix(_:)用法及代碼示例
- Swift Float -(_:)用法及代碼示例
- Swift FlattenSequence max(by:)用法及代碼示例
- Swift Float80 /(_:_:)用法及代碼示例
- Swift Float ...(_:_:)用法及代碼示例
- Swift FloatingPointRoundingRule.toNearestOrAwayFromZero用法及代碼示例
- Swift Float16 ...(_:_:)用法及代碼示例
- Swift FloatingPointRoundingRule.up用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 FixedWidthInteger &>>=(_:_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。