Intrinsics1 min read
asuint
Reinterprets bits as unsigned integers.
Reading Time
1 min
Word Count
94
Sections
7
Try It Live
Test asuint in a live shader
Open the playground, start from a visual preset, and wire asuint into the fragment stage to see how it behaves with real values.
Open PlaygroundThe asuint function reinterprets a value's bit pattern as an unsigned integer. It does not clamp, round, or convert numerically.
Live Demo
Signature
bwsl
asuint :: (float x) -> uint
asuint :: (int x) -> uint
asuint :: (floatN x) -> uintN
asuint :: (intN x) -> uintN
Parameters
| Parameter | Type | Description |
|---|---|---|
x | float, int, or vector form | Source bits to reinterpret |
Return Value
Returns a uint or uintN with the same bits as x.
Example
bwsl
float value = 1.0;
uint bits = asuint(value);
uint exponent = bitfield_extract(bits, 23, 8);Compiled Output
When compiled to GLSL:
glsl
floatBitsToUint(x)
When compiled to HLSL:
hlsl
asuint(x)
When compiled to Metal:
metal
as_type<uint>(x)
See Also
- asfloat - Reinterpret bits as floats
- asint - Reinterpret bits as signed integers
- bitfield_extract - Extract packed bit fields