Operator 演算子

&>>=(_:_:)

Calculates the result of shifting a value’s binary representation the specified number of digits to the right, masking the shift amount to the type’s bit width, and stores the result in the left-hand-side variable. ある値のバイナリ表現を指定された桁数だけ右にシフトする結果を計算します、シフト量をその型のもつビット幅にマスクしています、そして結果を左手側の変数に格納します。

Declaration 宣言

static func &>>= (lhs: inout UInt8, rhs: UInt8)

Parameters パラメータ

lhs

The value to shift. シフトする値。

rhs

The number of bits to shift lhs to the right. If rhs is outside the range 0..<lhs.bitWidth, it is masked to produce a value within that range. このビット数をlhsから右へとシフトします。rhsが範囲0..<lhs.bitWidthの外側ならば、それはマスクされてその範囲内の値を生み出します。

Discussion 解説

The &>>= operator performs a masking shift, where the value passed as rhs is masked to produce a value in the range 0..<lhs.bitWidth. The shift is performed using this masked value. &>>=演算子は、マスクするシフトを実行します、そこにおいてrhsとして渡される値はマスクされることで範囲0..<lhs.bitWidthの中の値を生成します。シフトは、このマスクされた値を使って実行されます。

The following example defines x as an instance of UInt8, an 8-bit, unsigned integer type. If you use 2 as the right-hand-side value in an operation on x, the shift amount requires no masking. 以下の例は、xUInt8のインスタンス、ある8ビットの、符号なし整数型として定義します。あなたが2を右手側の値としてxに関する演算において使うならば、シフト量はマスクを必要としません。


var x: UInt8 = 30                 // 0b00011110
x &>>= 2
// x == 7                         // 0b00000111

However, if you use 19 as rhs, the operation first bitmasks rhs to 3, and then uses that masked value as the number of bits to shift lhs. しかしながら、あなたが19rhsとして使うならば、この演算は最初にrhs3にビットマスクして、それからそのマスクされた値をビット数として使うことでlhsをシフトします。


var y: UInt8 = 30                 // 0b00011110
y &>>= 19
// y == 3                         // 0b00000011

Relationships 関係

From Protocol 由来プロトコル