---
title: "bitcast / floatBitsToUint: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점"
description: "같은 비트를 다른 형식으로 해석합니다. 수치 변환은 하지 않습니다. 부동소수점 인코딩을 확인하거나 압축 데이터를 해석할 때 사용합니다. 예제는 유한한 정규수와 영을 사용합니다."
url: https://typeshade.dev/ko/reference/functions/bitcast/
language: ko
---

# `bitcast`

함수

같은 비트를 다른 형식으로 해석합니다. 수치 변환은 하지 않습니다.

**다른 언어의 관련 이름**

관련 연산은 인수, 지원 범위와 의미가 다를 수 있습니다. 다른 언어의 이름을 TypeShade 별칭으로 사용할 수는 없습니다. 지원하는 형태와 제한은 대상 언어에 따라 다릅니다.

- GLSL: `floatBitsToUint`
- GLSL: `floatBitsToInt`
- GLSL: `uintBitsToFloat`
- GLSL: `intBitsToFloat`
- HLSL: `asuint`
- HLSL: `asfloat`

[구문](https://typeshade.dev/ko/reference/functions/bitcast/#syntax)

## 예제 비교

같은 비트 패턴을 16진수 부호 없는 정수로 표시합니다. 입력의 숫자값을 정수로 변환한 결과와는 다릅니다.

**예제 1`bitcast<u32>(0.)`**

**결과**

`0x00000000`

정수의 이진 표현: `0`

**예제 2`bitcast<u32>(1.)`**

**결과**

`0x3f800000`

정수의 이진 표현: `1065353216`

**예제 3`bitcast<u32>(-2.)`**

**결과**

`0xc0000000`

정수의 이진 표현: `3221225472`

예제는 설명용 계산 모델이며 GPU를 실행하지 않습니다. 정확한 호출 형식은 아래 컴파일러 참고 자료에서 설명합니다. 소수 결과는 표시할 때 반올림했습니다. 각 예제는 명시한 전제를 따릅니다. 실제 셰이더의 결과는 대상 언어의 정밀도와 실행 규칙에 따릅니다.

## 활용

부동소수점 인코딩을 확인하거나 압축 데이터를 해석할 때 사용합니다.

## 입력 범위와 주의사항

예제는 유한한 정규수와 영을 사용합니다. 이 컴파일러에서 NaN과 비정규수 비트 패턴은 이식 가능한 저장 인코딩이 아닙니다.

셰이더의 입력 규칙과 정밀도는 [WGSL](https://www.w3.org/TR/WGSL/)과 [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf)에서 규정합니다.

## 관련 함수

- [`f32`](https://typeshade.dev/ko/reference/functions/f32/)
- [`u32`](https://typeshade.dev/ko/reference/functions/u32/)
- [`pack2x16float`](https://typeshade.dev/ko/reference/functions/pack2x16float/)

시그니처와 이름 아래 문장, 컴파일러 메시지는 커밋 af54ddad5의 컴파일러가 쓴 영어 원문입니다.

Reads the same 32 bits as another type, each component of a vector the same way: `bitcast<u32>(x)` on an `f32`, `bitcast<f32>(x)` on a `u32`, `bitcast<vec4u>(v)` on a `vec4` and `bitcast<vec4>(w)` on a `vec4u`, `floatBitsToUint` / `uintBitsToFloat` on GLSL ES 3.00.

## 구문

```ts
declare function bitcast<T extends u32 | f32 | vec2u | vec3u | vec4u | vec2 | vec3 | vec4>(e: BitcastArg<T>): T
```

시그니처에는 앰비언트 파일이 스스로 쓰려고 선언한 타입이 나올 수 있습니다. 아래가 그 선언입니다.

**`BitcastArg`**

`type BitcastArg<T> = T extends vec2u ? vec2 : T extends vec3u ? vec3 : T extends vec4u ? vec4 : T extends vec2 ? vec2u : T extends vec3 ? vec3u : T extends vec4 ? vec4u : typeof u32Tag extends keyof T ? f32 : u32`

## 매개변수

- `e` `BitcastArg<T>`

## 반환값

`T`

## 설명

It reinterprets, it does not convert; `u32(x)` is the conversion. A NaN or subnormal bit pattern has no portable answer, so keep an integer word in a `storage<array<u32>>` or `storage<array<vec4u>>` binding, not in the bits of an `f32`.

## 예제

- [`gallery/packing-bitcast/packing-bitcast.shade.ts`](https://typeshade.dev/ko/guide/examples/packing-bitcast/)

## 함께 보기

- [함수](https://typeshade.dev/ko/reference/functions/)
