> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Hex.fromNumber

:::info
`Hex.fromNumber` is a re-export of ox's [`Hex.fromNumber`](https://oxlib.sh/api/Hex/fromNumber). Refer to the ox documentation for the full reference.
:::

Encodes a number or bigint into a [`Hex.Hex`](/docs/utilities/hex/types#hex) value.

## Imports

```ts
import { Hex } from 'viem/utils'
```

## Examples

```ts twoslash
// @noErrors
import { Hex } from 'viem/utils'

Hex.fromNumber(420)
// @log: '0x1a4'

Hex.fromNumber(420, { size: 32 })
// @log: '0x00000000000000000000000000000000000000000000000000000000000001a4'
```

## Definition

```ts
function fromNumber(
  value: number | bigint,
  options?: fromNumber.Options,
): Hex
```

## Parameters

### value

* **Type:** `number | bigint`

The number or bigint value to encode.

### options

* **Type:** `fromNumber.Options`
* **Optional**

Options.

#### options.signed

* **Type:** `boolean`
* **Optional**

Whether or not the number of a signed representation.

#### options.size

* **Type:** `number`
* **Optional**

The size (in bytes) of the output hex value.

## Return Type

The encoded [`Hex.Hex`](/docs/utilities/hex/types#hex) value.

`Hex`
