---
title: "bitCast(_:to:)"
framework: Swift
role: symbol
role_heading: Function
platforms: [iOS 8.0+, iPadOS 8.0+, Mac Catalyst 13.0+, macOS 10.10+, tvOS 9.0+, visionOS 1.0+, watchOS 2.0+]
path: "swift/bitcast(_:to:)"
---

# bitCast(_:to:)

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

## Declaration

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

Return Value A new instance of type U, cast from original.

## Discussion

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

## See Also

### Safe Access to Raw Bytes

- [FullyInhabited](swift/fullyinhabited.md)
- [ConvertibleFromBytes](swift/convertiblefrombytes.md)
- [ConvertibleToBytes](swift/convertibletobytes.md)
- [ByteOrder](swift/byteorder.md)
