---
title: "pack4xU8: shader function examples, uses and input limits"
description: "Integer byte packing combines components into one word. Use it to reduce storage or bandwidth when the reduced precision is acceptable."
url: https://typeshade.dev/reference/functions/pack4xU8/
language: en
---

# `pack4xU8`

Function

Integer byte packing combines components into one word.

## Compare examples

Compare the components, hexadecimal word, and recovered values. Notice which component occupies the low field.

**Example 1`pack4xU8(vec4u(1, 2, 3, 4))`**

`1` `2` `3` `4`

Components in this example

**Result**

`0x04030201`

Word in binary: `67305985`

**Example 2`pack4xU8(vec4u(255, 255, 255, 255))`**

`255` `255` `255` `255`

Components in this example

**Result**

`0xffffffff`

Word in binary: `4294967295`

**Example 3`pack4xU8(vec4u(300, 300, 300, 300))`**

`300` `300` `300` `300`

Components in this example

**Result**

`0x2c2c2c2c`

Word in binary: `741092396`

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use it to reduce storage or bandwidth when the reduced precision is acceptable.

## Inputs and limits

This variant keeps only the low byte of each component; it does not clamp. These integer byte operations are WebGPU-only in this compiler.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`unpack4xU8`](https://typeshade.dev/reference/functions/unpack4xU8/)
- [`bitcast`](https://typeshade.dev/reference/functions/bitcast/)

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Packs the low byte of each component of a `vec4u` into a `u32`, component 0 in the low byte.

## Syntax

```ts
declare function pack4xU8(a0: vec4u): u32
declare function pack4xU8(e: vec4u): u32
```

## Parameters

- `e` `vec4u`

## Return value

`u32`

## Description

A component that does not fit is TRUNCATED, not clamped; `pack4xU8Clamp` saturates instead. Not supported yet on the WebGL2 tier.

## Targets

**WGSL**

`pack4xU8(a)`

**GLSL ES 3.00**

`pack4xU8` is not supported yet on the WebGL2 tier

## Examples

- [`gallery/packed-bytes/packed-bytes.shade.ts`](https://typeshade.dev/guide/examples/packed-bytes/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#packing)
