> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# BrandedHex

> Auto-generated API documentation

[**@tevm/voltaire**](../../index.mdx)

***

[@tevm/voltaire](../../index.mdx) / [index](../index.mdx) / BrandedHex

# BrandedHex

## Variables

### BrandedHex

> `const` **BrandedHex**: `object`

Defined in: [src/primitives/Hex/internal-index.ts:63](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/internal-index.ts#L63)

#### Type Declaration

##### assertSize()

> **assertSize**: \<`TSize`>(`hex`, `targetSize`) => [`Sized`](../../primitives/Hex.mdx#sized)\<`TSize`>

Assert hex has specific size

###### Type Parameters

###### TSize

`TSize` *extends* `number`

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to check

###### targetSize

`TSize`

Expected byte size

###### Returns

[`Sized`](../../primitives/Hex.mdx#sized)\<`TSize`>

Sized hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If size doesn't match

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const sized = Hex.assertSize(hex, 2); // Sized<2>
```

##### clone()

> **clone**: (`hex`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Create a copy of a Hex string

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to clone

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Copy of the hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex1 = Hex.from("0x1234");
const hex2 = Hex.clone(hex1);
console.log(Hex.equals(hex1, hex2)); // true
```

##### concat()

> **concat**: (...`hexes`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Concatenate multiple hex strings

###### Parameters

###### hexes

...[`HexType`](../../primitives/Hex.mdx#hextype)\[]

Hex strings to concatenate

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Concatenated hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If missing 0x prefix or contains invalid hex characters

###### Throws

If hex has odd number of digits

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.concat('0x12', '0x34', '0x56'); // '0x123456'
```

##### equals()

> **equals**: (`hex`, `other`) => `boolean`

Check if two hex strings are equal

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

First hex string

###### other

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to compare with

###### Returns

`boolean`

True if equal

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.equals(hex, Hex.from('0x1234')); // true
```

##### from()

> **from**: (`value`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Create Hex from string or bytes

###### Parameters

###### value

Hex string or bytes

`string` | `Uint8Array`\<`ArrayBufferLike`>

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const hex2 = Hex.from(new Uint8Array([0x12, 0x34]));
```

##### fromBigInt()

> **fromBigInt**: (`value`, `size?`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Convert bigint to hex

###### Parameters

###### value

`bigint`

BigInt to convert

###### size?

`number`

Optional byte size for padding

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.fromBigInt(255n);      // '0xff'
Hex.fromBigInt(255n, 32);  // '0x00...00ff' (32 bytes)
```

##### fromBoolean()

> **fromBoolean**: (`value`) => [`Sized`](../../primitives/Hex.mdx#sized)\<`1`>

Convert boolean to hex

###### Parameters

###### value

`boolean`

Boolean to convert

###### Returns

[`Sized`](../../primitives/Hex.mdx#sized)\<`1`>

Hex string ('0x01' for true, '0x00' for false)

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.fromBoolean(true);  // '0x01'
Hex.fromBoolean(false); // '0x00'
```

##### fromBytes()

> **fromBytes**: (`bytes`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Convert bytes to hex

###### Parameters

###### bytes

`Uint8Array`

Byte array to convert

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.fromBytes(new Uint8Array([0x12, 0x34])); // '0x1234'
```

##### fromNumber()

> **fromNumber**: (`value`, `size?`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Convert number to hex

###### Parameters

###### value

`number`

Number to convert (must be safe integer)

###### size?

`number`

Optional byte size for padding

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If value exceeds Number.MAX\_SAFE\_INTEGER or is negative

###### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.fromNumber(255);     // '0xff'
Hex.fromNumber(255, 2);  // '0x00ff'
Hex.fromNumber(0x1234);  // '0x1234'
```

##### fromString()

> **fromString**: (`str`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Convert string to hex

###### Parameters

###### str

`string`

String to convert

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.fromString('hello'); // '0x68656c6c6f'
```

##### isHex()

> **isHex**: (`value`) => `value is HexType`

Check if string is valid hex

###### Parameters

###### value

`string`

String to validate

###### Returns

`value is HexType`

True if valid hex format

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.isHex('0x1234'); // true
Hex.isHex('1234');   // false
Hex.isHex('0xZZZZ'); // false
```

##### isSized()

> **isSized**: \<`TSize`>(`hex`, `targetSize`) => `hex is Sized<TSize>`

Check if hex has specific byte size

###### Type Parameters

###### TSize

`TSize` *extends* `number`

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to check

###### targetSize

`TSize`

Expected size in bytes

###### Returns

`hex is Sized<TSize>`

True if size matches

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.isSized(hex, 2); // true
```

##### pad()

> **pad**: (`hex`, `targetSize`) => `string`

Pad hex to target size (left-padded with zeros)

###### Parameters

###### hex

`string`

Hex string to pad

###### targetSize

`number`

Target size in bytes

###### Returns

`string`

Padded hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If hex exceeds target size

###### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const padded = Hex.pad(hex, 4); // '0x00001234'
Hex.pad('0x1234', 1); // throws Error (2 bytes > 1 byte target)
```

##### padRight()

> **padRight**: (`hex`, `targetSize`) => `string`

Pad hex to right (suffix with zeros)

###### Parameters

###### hex

`string`

Hex string to pad

###### targetSize

`number`

Target size in bytes

###### Returns

`string`

Right-padded hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const padded = Hex.padRight(hex, 4); // '0x12340000'
```

##### random()

> **random**: (`size`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Generate random hex of specific size

###### Parameters

###### size

`number`

Size in bytes

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Random hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const random = Hex.random(32); // random 32-byte hex
```

##### size()

> **size**: (`hex`) => `number`

Get byte size of hex

###### Parameters

###### hex

`string`

Hex string

###### Returns

`number`

Size in bytes

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.size(hex); // 2
```

##### slice()

> **slice**: (`hex`, `start`, `end?`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Slice hex string

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to slice

###### start

`number`

Start byte index

###### end?

`number`

End byte index (optional)

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Sliced hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If missing 0x prefix or contains invalid hex characters

###### Throws

If hex has odd number of digits

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x123456');
const sliced = Hex.slice(hex, 1); // '0x3456'
```

##### toBigInt()

> **toBigInt**: (`hex`) => `bigint`

Convert hex to bigint

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to convert

###### Returns

`bigint`

BigInt value

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0xff');
const big = Hex.toBigInt(hex); // 255n
```

##### toBoolean()

> **toBoolean**: (`hex`) => `boolean`

Convert hex to boolean (strict: only 0x0/0x00 or 0x1/0x01 are valid)

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to convert

###### Returns

`boolean`

Boolean value (true for 0x1/0x01, false for 0x0/0x00)

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If hex is not a valid boolean value (only 0 or 1 allowed)

###### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x01');
const bool = Hex.toBoolean(hex); // true
Hex.toBoolean('0x00'); // false
Hex.toBoolean('0x02'); // throws Error
```

##### toBytes()

> **toBytes**: (`hex`) => `Uint8Array`

Convert hex to bytes

###### Parameters

###### hex

Hex string to convert

`string` | [`HexType`](../../primitives/Hex.mdx#hextype)

###### Returns

`Uint8Array`

Byte array

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If missing 0x prefix or contains invalid hex characters

###### Throws

If hex has odd number of digits

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const bytes = Hex.toBytes(hex); // Uint8Array([0x12, 0x34])
```

##### toNumber()

> **toNumber**: (`hex`) => `number`

Convert hex to number

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to convert

###### Returns

`number`

Number value

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If hex represents value larger than MAX\_SAFE\_INTEGER

###### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0xff');
const num = Hex.toNumber(hex); // 255
```

##### toString()

> **toString**: (`hex`) => `string`

Convert hex to string

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to convert

###### Returns

`string`

Decoded string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If missing 0x prefix or contains invalid hex characters

###### Throws

If hex has odd number of digits

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x68656c6c6f');
const str = Hex.toString(hex); // 'hello'
```

##### trim()

> **trim**: (`hex`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Trim leading zeros from hex

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to trim

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Trimmed hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If missing 0x prefix or contains invalid hex characters

###### Throws

If hex has odd number of digits

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x00001234');
const trimmed = Hex.trim(hex); // '0x1234'
```

##### validate()

> **validate**: (`value`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Validate hex string

###### Parameters

###### value

`string`

String to validate as hex

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Validated hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If missing 0x prefix or contains invalid hex characters

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.validate('0x1234'); // HexType
```

##### xor()

> **xor**: (`hex`, `other`) => [`HexType`](../../primitives/Hex.mdx#hextype)

XOR with another hex string of same length

###### Parameters

###### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

First hex string

###### other

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to XOR with

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

XOR result

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

If missing 0x prefix or contains invalid hex characters

###### Throws

If hex has odd number of digits or lengths don't match

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x12');
const result = Hex.xor(hex, Hex.from('0x34')); // '0x26'
```

##### zero()

> **zero**: (`size`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Create zero-filled hex of specific size

###### Parameters

###### size

`number`

Size in bytes

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Zero-filled hex string

###### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

###### Since

0.0.0

###### Throws

###### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.zero(4); // '0x00000000'
```

## Functions

### assertSize()

> **assertSize**\<`TSize`>(`hex`, `targetSize`): [`Sized`](../../primitives/Hex.mdx#sized)\<`TSize`>

Defined in: [src/primitives/Hex/assertSize.ts:20](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/assertSize.ts#L20)

Assert hex has specific size

#### Type Parameters

##### TSize

`TSize` *extends* `number`

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to check

##### targetSize

`TSize`

Expected byte size

#### Returns

[`Sized`](../../primitives/Hex.mdx#sized)\<`TSize`>

Sized hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If size doesn't match

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const sized = Hex.assertSize(hex, 2); // Sized<2>
```

***

### clone()

> **clone**(`hex`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/clone.js:17](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/clone.js#L17)

Create a copy of a Hex string

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to clone

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Copy of the hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex1 = Hex.from("0x1234");
const hex2 = Hex.clone(hex1);
console.log(Hex.equals(hex1, hex2)); // true
```

***

### concat()

> **concat**(...`hexes`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/concat.ts:21](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/concat.ts#L21)

Concatenate multiple hex strings

#### Parameters

##### hexes

...[`HexType`](../../primitives/Hex.mdx#hextype)\[]

Hex strings to concatenate

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Concatenated hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If missing 0x prefix or contains invalid hex characters

#### Throws

If hex has odd number of digits

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.concat('0x12', '0x34', '0x56'); // '0x123456'
```

***

### equals()

> **equals**(`hex`, `other`): `boolean`

Defined in: [src/primitives/Hex/equals.ts:19](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/equals.ts#L19)

Check if two hex strings are equal

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

First hex string

##### other

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to compare with

#### Returns

`boolean`

True if equal

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.equals(hex, Hex.from('0x1234')); // true
```

***

### from()

> **from**(`value`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/from.ts:19](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/from.ts#L19)

Create Hex from string or bytes

#### Parameters

##### value

Hex string or bytes

`string` | `Uint8Array`\<`ArrayBufferLike`>

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const hex2 = Hex.from(new Uint8Array([0x12, 0x34]));
```

***

### fromBigInt()

> **fromBigInt**(`value`, `size?`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/fromBigInt.ts:19](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/fromBigInt.ts#L19)

Convert bigint to hex

#### Parameters

##### value

`bigint`

BigInt to convert

##### size?

`number`

Optional byte size for padding

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.fromBigInt(255n);      // '0xff'
Hex.fromBigInt(255n, 32);  // '0x00...00ff' (32 bytes)
```

***

### fromBoolean()

> **fromBoolean**(`value`): [`Sized`](../../primitives/Hex.mdx#sized)\<`1`>

Defined in: [src/primitives/Hex/fromBoolean.js:16](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/fromBoolean.js#L16)

Convert boolean to hex

#### Parameters

##### value

`boolean`

Boolean to convert

#### Returns

[`Sized`](../../primitives/Hex.mdx#sized)\<`1`>

Hex string ('0x01' for true, '0x00' for false)

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.fromBoolean(true);  // '0x01'
Hex.fromBoolean(false); // '0x00'
```

***

### fromBytes()

> **fromBytes**(`bytes`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/fromBytes.ts:17](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/fromBytes.ts#L17)

Convert bytes to hex

#### Parameters

##### bytes

`Uint8Array`

Byte array to convert

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.fromBytes(new Uint8Array([0x12, 0x34])); // '0x1234'
```

***

### fromNumber()

> **fromNumber**(`value`, `size?`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/fromNumber.js:18](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/fromNumber.js#L18)

Convert number to hex

#### Parameters

##### value

`number`

Number to convert (must be safe integer)

##### size?

`number`

Optional byte size for padding

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If value exceeds Number.MAX\_SAFE\_INTEGER or is negative

#### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.fromNumber(255);     // '0xff'
Hex.fromNumber(255, 2);  // '0x00ff'
Hex.fromNumber(0x1234);  // '0x1234'
```

***

### fromString()

> **fromString**(`str`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/fromString.ts:18](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/fromString.ts#L18)

Convert string to hex

#### Parameters

##### str

`string`

String to convert

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.fromString('hello'); // '0x68656c6c6f'
```

***

### isHex()

> **isHex**(`value`): `value is HexType`

Defined in: [src/primitives/Hex/isHex.ts:20](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/isHex.ts#L20)

Check if string is valid hex

#### Parameters

##### value

`string`

String to validate

#### Returns

`value is HexType`

True if valid hex format

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.isHex('0x1234'); // true
Hex.isHex('1234');   // false
Hex.isHex('0xZZZZ'); // false
```

***

### isSized()

> **isSized**\<`TSize`>(`hex`, `targetSize`): `hex is Sized<TSize>`

Defined in: [src/primitives/Hex/isSized.ts:19](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/isSized.ts#L19)

Check if hex has specific byte size

#### Type Parameters

##### TSize

`TSize` *extends* `number`

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to check

##### targetSize

`TSize`

Expected size in bytes

#### Returns

`hex is Sized<TSize>`

True if size matches

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.isSized(hex, 2); // true
```

***

### pad()

> **pad**(`hex`, `targetSize`): `string`

Defined in: [src/primitives/Hex/pad.js:21](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/pad.js#L21)

Pad hex to target size (left-padded with zeros)

#### Parameters

##### hex

`string`

Hex string to pad

##### targetSize

`number`

Target size in bytes

#### Returns

`string`

Padded hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If hex exceeds target size

#### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const padded = Hex.pad(hex, 4); // '0x00001234'
Hex.pad('0x1234', 1); // throws Error (2 bytes > 1 byte target)
```

***

### padRight()

> **padRight**(`hex`, `targetSize`): `string`

Defined in: [src/primitives/Hex/padRight.js:20](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/padRight.js#L20)

Pad hex to right (suffix with zeros)

#### Parameters

##### hex

`string`

Hex string to pad

##### targetSize

`number`

Target size in bytes

#### Returns

`string`

Right-padded hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const padded = Hex.padRight(hex, 4); // '0x12340000'
```

***

### random()

> **random**(`size`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/random.ts:18](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/random.ts#L18)

Generate random hex of specific size

#### Parameters

##### size

`number`

Size in bytes

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Random hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const random = Hex.random(32); // random 32-byte hex
```

***

### size()

> **size**(`hex`): `number`

Defined in: [src/primitives/Hex/size.js:16](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/size.js#L16)

Get byte size of hex

#### Parameters

##### hex

`string`

Hex string

#### Returns

`number`

Size in bytes

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.size(hex); // 2
```

***

### slice()

> **slice**(`hex`, `start`, `end?`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/slice.ts:24](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/slice.ts#L24)

Slice hex string

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to slice

##### start

`number`

Start byte index

##### end?

`number`

End byte index (optional)

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Sliced hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If missing 0x prefix or contains invalid hex characters

#### Throws

If hex has odd number of digits

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x123456');
const sliced = Hex.slice(hex, 1); // '0x3456'
```

***

### toBigInt()

> **toBigInt**(`hex`): `bigint`

Defined in: [src/primitives/Hex/toBigInt.ts:18](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/toBigInt.ts#L18)

Convert hex to bigint

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to convert

#### Returns

`bigint`

BigInt value

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0xff');
const big = Hex.toBigInt(hex); // 255n
```

***

### toBoolean()

> **toBoolean**(`hex`): `boolean`

Defined in: [src/primitives/Hex/toBoolean.js:20](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/toBoolean.js#L20)

Convert hex to boolean (strict: only 0x0/0x00 or 0x1/0x01 are valid)

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to convert

#### Returns

`boolean`

Boolean value (true for 0x1/0x01, false for 0x0/0x00)

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If hex is not a valid boolean value (only 0 or 1 allowed)

#### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x01');
const bool = Hex.toBoolean(hex); // true
Hex.toBoolean('0x00'); // false
Hex.toBoolean('0x02'); // throws Error
```

***

### toBytes()

> **toBytes**(`hex`): `Uint8Array`

Defined in: [src/primitives/Hex/toBytes.ts:21](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/toBytes.ts#L21)

Convert hex to bytes

#### Parameters

##### hex

Hex string to convert

`string` | [`HexType`](../../primitives/Hex.mdx#hextype)

#### Returns

`Uint8Array`

Byte array

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If missing 0x prefix or contains invalid hex characters

#### Throws

If hex has odd number of digits

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const bytes = Hex.toBytes(hex); // Uint8Array([0x12, 0x34])
```

***

### toNumber()

> **toNumber**(`hex`): `number`

Defined in: [src/primitives/Hex/toNumber.js:18](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/toNumber.js#L18)

Convert hex to number

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to convert

#### Returns

`number`

Number value

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If hex represents value larger than MAX\_SAFE\_INTEGER

#### Example

```javascript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0xff');
const num = Hex.toNumber(hex); // 255
```

***

### toString()

> **toString**(`hex`): `string`

Defined in: [src/primitives/Hex/toString.ts:22](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/toString.ts#L22)

Convert hex to string

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to convert

#### Returns

`string`

Decoded string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If missing 0x prefix or contains invalid hex characters

#### Throws

If hex has odd number of digits

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x68656c6c6f');
const str = Hex.toString(hex); // 'hello'
```

***

### trim()

> **trim**(`hex`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/trim.ts:22](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/trim.ts#L22)

Trim leading zeros from hex

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to trim

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Trimmed hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If missing 0x prefix or contains invalid hex characters

#### Throws

If hex has odd number of digits

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x00001234');
const trimmed = Hex.trim(hex); // '0x1234'
```

***

### validate()

> **validate**(`value`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/validate.ts:19](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/validate.ts#L19)

Validate hex string

#### Parameters

##### value

`string`

String to validate as hex

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Validated hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If missing 0x prefix or contains invalid hex characters

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.validate('0x1234'); // HexType
```

***

### xor()

> **xor**(`hex`, `other`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/xor.ts:24](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/xor.ts#L24)

XOR with another hex string of same length

#### Parameters

##### hex

[`HexType`](../../primitives/Hex.mdx#hextype)

First hex string

##### other

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string to XOR with

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

XOR result

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If missing 0x prefix or contains invalid hex characters

#### Throws

If hex has odd number of digits or lengths don't match

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x12');
const result = Hex.xor(hex, Hex.from('0x34')); // '0x26'
```

***

### zero()

> **zero**(`size`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Hex/zero.ts:18](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/zero.ts#L18)

Create zero-filled hex of specific size

#### Parameters

##### size

`number`

Size in bytes

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Zero-filled hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
Hex.zero(4); // '0x00000000'
```

## References

### HexType

Renames and re-exports [HexBrand](../../primitives/Hex.mdx#hexbrand)

***

### InvalidCharacterError

Re-exports [InvalidCharacterError](../../primitives/Hex.mdx#invalidcharactererror)

***

### InvalidFormatError

Re-exports [InvalidFormatError](../../primitives/Hex.mdx#invalidformaterror)

***

### InvalidHexCharacterError

Re-exports [InvalidHexCharacterError](../../primitives/Hex.mdx#invalidhexcharactererror)

***

### InvalidHexFormatError

Re-exports [InvalidHexFormatError](../../primitives/Hex.mdx#invalidhexformaterror)

***

### InvalidHexLengthError

Re-exports [InvalidHexLengthError](../../primitives/Hex.mdx#invalidhexlengtherror)

***

### InvalidLengthError

Re-exports [InvalidLengthError](../../primitives/Hex.mdx#invalidlengtherror)

***

### OddLengthError

Re-exports [OddLengthError](../../primitives/Hex.mdx#oddlengtherror)

***

### OddLengthHexError

Re-exports [OddLengthHexError](../../primitives/Hex.mdx#oddlengthhexerror)
