<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UInt8/&__(_:_:)-5m6yb",
  "metadataVersion" : "0.1.0",
  "role" : "Operator",
  "symbol" : {
    "kind" : "Operator",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s17FixedWidthIntegerPsE3alloiyxx_xtFZ::SYNTHESIZED::s:s5UInt8V"
  },
  "title" : "&<<(_:_:)"
}
-->

# &<<(_:_:)

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
```

## 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

Use the masking left 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 left 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 == 120                       // 0b01111000
```

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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)