Skip to main content

Try it Live

Run Bytes examples in the interactive playground
Type-Safe Primitive - Bytes16 provides compile-time guarantees for 16-byte values like UUIDs and medium hashes.

Overview

Bytes16 is a branded Uint8Array type representing exactly 16 bytes (128 bits). It provides strict size validation and type safety for fixed-size byte values.

Use Cases

UUIDs (128-bit)
Medium Hashes
Fixed-Size Keys

Type Safety

Bytes16 uses Symbol branding for compile-time safety:
This prevents mixing different byte types:

Hex Variants

Bytes16 also supports hex string variants with case flags:
For generic byte concepts, see Bytes.

Constructors

from

Create Bytes16 from hex string or bytes:

fromHex

Create from hex string with strict validation:

fromBytes

Create from Uint8Array with size check:

zero

Create zero-filled Bytes16:

Conversions

toHex

Convert to hex string:

toUint8Array

Convert to raw bytes:

Operations

equals

Check equality:

compare

Compare two values:

clone

Create independent copy:

isZero

Check if all zeros:

size

Get size (always 16):

Constants

SIZE

Bytes16 size in bytes:

ZERO

Zero-filled constant:

Error Handling

Bytes16 validates size strictly:
  • Bytes32 - 256-bit fixed-size bytes (most common)
  • Bytes64 - 512-bit fixed-size bytes
  • Keccak256 - 256-bit cryptographic hashes
  • Hex - Variable-length hex strings