# CompactSize.toHex

Encodes an integer using Bitcoin's CompactSize variable-length encoding and returns it as [`Hex.Hex`](/api/Hex/types#hex).

## Imports

:::code-group
```ts [Named]
import { CompactSize } from 'ox'
```

```ts [Entrypoint]
import * as CompactSize from 'ox/CompactSize'
```
:::

## Examples

```ts twoslash
import { CompactSize } from 'ox'

const hex = CompactSize.toHex(252)
// '0xfc'
```

## Definition

```ts
function toHex(
  value: bigint | number,
): Hex.Hex
```

**Source:** [src/core/CompactSize.ts](https://github.com/wevm/ox/blob/main/src/core/CompactSize.ts#L204)

## Parameters

### value

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

The integer to encode.

## Return Type

The CompactSize-encoded hex string.

`Hex.Hex`
