Operator (Default implementation)swift 6.0.1Swift
&>>(_:_:)
Returns 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.
static func &>> (lhs: Self, rhs: Self) -> Self
Parameters
Use the masking right shift operator (&>>
) when you need to perform a shift and are sure that the shift amount is in the range 0..<lhs.bitWidth
. Before shifting, the masking right shift operator masks the shift to this range. The shift is performed using this masked value.
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.
let x: UInt8 = 30 // 0b00011110
let y = x &>> 2
// y == 7 // 0b00000111
However, if you use 8
as the shift amount, the method first masks the shift amount to zero, and then performs the shift, resulting in no change to the original value.
let z = x &>> 8
// z == 30 // 0b00011110
If the bit width of the shifted integer type is a power of two, masking is performed using a bitmask; otherwise, masking is performed using a modulo operation.
Implements
static func &>> (lhs: Self, rhs: Self
) -> Self Returns 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.
Other members in extension
Type members
init?(String
) Creates a new integer value from the given string.
init<T>(T
) Creates an integer from the given floating-point value, rounding toward zero. Any fractional part of the value passed as
source
is removed.init?<S>(S, radix: Int
) Creates a new integer value from the given string and radix.
init(bigEndian: Self
) Creates an integer from its big-endian representation, changing the byte order if necessary.
init<Other>(clamping: Other
) Creates a new instance with the representable value that’s closest to the given integer.
init?<T>(exactly: T
) Creates an integer from the given floating-point value, if it can be represented exactly.
init(littleEndian: Self
) Creates an integer from its little-endian representation, changing the byte order if necessary.
init<T>(truncatingIfNeeded: T
) Creates a new instance from the bit pattern of the given instance by truncating or sign-extending if needed to fit this type.
static func random(in: ClosedRange<Self>
) -> Self Returns a random value within the specified range.
static func random(in: Range<Self>
) -> Self Returns a random value within the specified range.
static func random<T>(in: ClosedRange<Self>, using: inout T
) -> Self Returns a random value within the specified range, using the given generator as a source for randomness.
static func random<T>(in: Range<Self>, using: inout T
) -> Self Returns a random value within the specified range, using the given generator as a source for randomness.
static func &* (lhs: Self, rhs: Self
) -> Self static func &*= (lhs: inout Self, rhs: Self
) Multiplies two values and stores the result in the left-hand-side variable, wrapping any overflow.
static func &+ (lhs: Self, rhs: Self
) -> Self Returns the sum of the two given values, wrapping the result in case of any overflow.
static func &+= (lhs: inout Self, rhs: Self
) Adds two values and stores the result in the left-hand-side variable, wrapping any overflow.
static func &- (lhs: Self, rhs: Self
) -> Self Returns the difference of the two given values, wrapping the result in case of any overflow.
static func &-= (lhs: inout Self, rhs: Self
) Subtracts the second value from the first and stores the difference in the left-hand-side variable, wrapping any overflow.
static func &<< <Other>(lhs: Self, rhs: Other
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width.
static func &<< (lhs: Self, rhs: Self
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width.
static func &<<= <Other>(lhs: inout Self, rhs: Other
) Returns the result of shifting a value’s binary representation the specified number of digits to the left, masking the shift amount to the type’s bit width, and stores the result in the left-hand-side variable.
static func &>> <Other>(lhs: Self, rhs: Other
) -> Self Returns 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.
static func &>>= <Other>(lhs: inout Self, rhs: Other
) 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.
static func << <Other>(lhs: Self, rhs: Other
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the left.
static func <<= <Other>(lhs: inout Self, rhs: Other
) static func >> <Other>(lhs: Self, rhs: Other
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the right.
static func >>= <Other>(lhs: inout Self, rhs: Other
) static func ~ (x: Self
) -> Self Returns the inverse of the bits set in the argument.
Instance members
var bigEndian: Self
The big-endian representation of this integer.
var bitWidth: Int
The number of bits in the binary representation of this value.
var littleEndian: Self
The little-endian representation of this integer.
func multipliedFullWidth(by: Self
) -> (high: Self, low: Self.Magnitude)