<!--
{
  "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/Int/~(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Operator",
  "symbol" : {
    "kind" : "Operator",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s17FixedWidthIntegerPsE1topyxxFZ::SYNTHESIZED::s:Si"
  },
  "title" : "~(_:)"
}
-->

# ~(_:)

Returns the inverse of the bits set in the argument.

```
static func ~ (x: Self) -> Self
```

## Discussion

The bitwise NOT operator (`~`) is a prefix operator that returns a value
in which all the bits of its argument are flipped: Bits that are `1` in
the argument are `0` in the result, and bits that are `0` in the argument
are `1` in the result. This is equivalent to the inverse of a set. For
example:

```
let x: UInt8 = 5        // 0b00000101
let notX = ~x           // 0b11111010
```

Performing a bitwise NOT operation on 0 returns a value with every bit
set to `1`.

```
let allOnes = ~UInt8.min   // 0b11111111
```

> Complexity: O(1).

---

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)