Returns the result of shifting a value’s binary representation the specified number of digits to the right.
Required. Default implementations provided.
- Xcode 10.0+
- Swift Standard Library
The value to shift.
The number of bits to shift
lhsto the right.
>> operator performs a smart shift, which defines a result for a shift of any value.
Using a negative value for
rhsperforms a left shift using
Using a value for
rhsthat is greater than or equal to the bit width of
lhsis an overshift. An overshift results in
-1for a negative value of
0for a nonnegative value.
Using any other value for
rhsperforms a right shift on
lhsby that amount.
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 value is shifted right by two bits.
If you use
x is overshifted such that all of its bits are set to zero.
Using a negative value as
rhs is the same as performing a left shift using
Right shift operations on negative values “fill in” the high bits with ones instead of zeros.