<!--
{
  "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/bitCast(_:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s7bitCast_2toq_x_q_mts18ConvertibleToBytesRzs0d4FromF0R_r0_lF"
  },
  "title" : "bitCast(_:to:)"
}
-->

# bitCast(_:to:)

Returns the bits of the given instance, interpreted as having the specified
type.

```
func bitCast<T, U>(_ original: T, to type: U.Type) -> U where T : ConvertibleToBytes, U : ConvertibleFromBytes
```

## Parameters

`original`

The instance to cast to `type`.

`type`

The type to cast `original` to.

## Return Value

A new instance of type `U`, cast from `original`.

## Discussion

`T` and `U` must have the same-sized memory representation.
If they don’t, this function will trap.

---

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)