> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Swift UInt64

`UInt64` is a value type in Swift representing a 64-bit unsigned integer. It stores non-negative whole numbers using exactly 8 bytes of memory, providing a fixed-width numeric representation that remains strictly 64 bits wide regardless of the underlying platform's architecture (unlike `UInt`, which scales to the platform's word size).

Because it is an unsigned type, it allocates all 64 bits to the magnitude of the number, omitting the sign bit. This yields the following mathematical bounds:

* **Minimum Value:** `0`
* **Maximum Value:** `18,446,744,073,709,551,615` ($2^{64} - 1$)

## Syntax and Initialization

You can instantiate a `UInt64` using integer literals, explicit type annotation, or by converting from other numeric types. Swift does not implicitly convert between integer types, so typecasting is strictly required when mixing `UInt64` with types like `Int` or `UInt32`.

```swift theme={"dark"}
// Explicit type annotation
let defaultZero: UInt64 = 0
let hexLiteral: UInt64 = 0xFFFFFFFFFFFFFFFF

// Accessing static boundary properties
let absoluteMin = UInt64.min // 0
let absoluteMax = UInt64.max // 18446744073709551615

// Explicit conversion from a signed integer
let standardInt: Int = 2048
let convertedUInt64 = UInt64(standardInt)

// Explicit conversion from a smaller unsigned integer
let smallUInt: UInt8 = 255
let expandedUInt64 = UInt64(smallUInt)
```

## Overflow and Underflow Behavior

By default, Swift prevents integer overflow and underflow. If an arithmetic operation on a `UInt64` results in a value outside its 64-bit bounds, the program will trigger a runtime trap.

To intentionally allow wrapping behavior at the bit level, Swift provides masking arithmetic operators (`&+`, `&-`, `&*`).

```swift theme={"dark"}
var boundaryValue = UInt64.max

// Standard addition causes a runtime crash (Overflow)
// boundaryValue += 1 

// Masking addition wraps the 64-bit integer back to 0
let wrappedValue = boundaryValue &+ 1 

var zeroValue = UInt64.min

// Masking subtraction wraps the 64-bit integer to UInt64.max
let underflowValue = zeroValue &- 1 
```

## Protocol Conformances

Under the hood, `UInt64` is implemented as a struct. It conforms to a robust hierarchy of Swift standard library protocols, dictating its capabilities:

* **`FixedWidthInteger` & `BinaryInteger`**: Guarantees a specific bit width, enabling bitwise operations (`~`, `&`, `|`, `^`, `<<`, `>>`) and providing access to properties like `leadingZeroBitCount` and `nonzeroBitCount`.
* **`UnsignedInteger`**: Semantically enforces the lack of a sign bit.
* **`Hashable` & `Equatable`**: Allows `UInt64` to be compared for equality (`==`, `!=`) and used as keys in `Dictionary` or elements in `Set`.
* **`Comparable`**: Enables relational operators (`<`, `>`, `<=`, `>=`).
* **`Codable`**: Provides out-of-the-box support for serialization and deserialization (e.g., JSON encoding).

```swift theme={"dark"}
let bitwiseTarget: UInt64 = 0b1010_1010
let shifted = bitwiseTarget << 2 // 0b10_1010_1000

let zeroCount = bitwiseTarget.leadingZeroBitCount // 56
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Swift Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
