Operator

&<<=(_:_:)

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.

Declaration

static func &<<= (lhs: inout Int, rhs: Int)

Parameters

lhs

The value to shift.

rhs

The number of bits to shift lhs to the left. If rhs is outside the range 0..<lhs.bitWidth, it is masked to produce a value within that range.

Discussion

The &<<= operator performs a masking shift, where the value used as rhs is masked to produce a value in the range 0..<lhs.bitWidth. 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.

var x: UInt8 = 30                 // 0b00011110
x &<<= 2
// x == 120                       // 0b01111000

However, if you pass 19 as rhs, the method first bitmasks rhs to 3, and then uses that masked value as the number of bits to shift lhs.

var y: UInt8 = 30                 // 0b00011110
y &<<= 19
// y == 240                       // 0b11110000

Relationships

From Protocol

See Also

Bit Shift

static func << <Other>(Int, Other) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the left.

static func << <RHS>(Int, RHS) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the left.

static func <<= <Other>(inout Int, Other)

Stores the result of shifting a value’s binary representation the specified number of digits to the left in the left-hand-side variable.

static func >> <Other>(Int, Other) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the right.

static func >> <RHS>(Int, RHS) -> Int

Returns the result of shifting a value’s binary representation the specified number of digits to the right.

static func >>= <Other>(inout Int, Other)

Stores the result of shifting a value’s binary representation the specified number of digits to the right in the left-hand-side variable.

static func &<< (Int, Int) -> Int

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 &<< (Int, Int) -> Int

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>(Int, Other) -> Int

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>(inout Int, 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 &>> (Int, Int) -> Int

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 &>> (Int, Int) -> Int

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>(Int, Other) -> Int

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 &>>= (inout Int, Int)

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>(inout Int, 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.