# PackingUtils

*External library used to pack and unpack values*

## pack

```solidity
function pack(uint256[] _values, uint256[] _bitLengths) external pure returns (uint256 packed)
```

*Packs values array into a single uint256*

### Parameters

| Name         | Type       | Description                              |
| ------------ | ---------- | ---------------------------------------- |
| \_values     | uint256\[] | values to pack                           |
| \_bitLengths | uint256\[] | corresponding bit lengths for each value |

## unpack

```solidity
function unpack(uint256 _packed, uint256[] _bitLengths) external pure returns (uint256[] values)
```

*Unpacks a single uint256 into an array of values*

### Parameters

| Name         | Type       | Description                              |
| ------------ | ---------- | ---------------------------------------- |
| \_packed     | uint256    | packed value                             |
| \_bitLengths | uint256\[] | corresponding bit lengths for each value |

## unpack256To64

```solidity
function unpack256To64(uint256 _packed) external pure returns (uint64 a, uint64 b, uint64 c, uint64 d)
```

*Unpacks a single uint256 into 4 uint64 values*

### Parameters

| Name     | Type    | Description  |
| -------- | ------- | ------------ |
| \_packed | uint256 | packed value |

### Return Values

| Name | Type   | Description      |
| ---- | ------ | ---------------- |
| a    | uint64 | returned value 1 |
| b    | uint64 | returned value 2 |
| c    | uint64 | returned value 3 |
| d    | uint64 | returned value 4 |

## unpackTriggerOrder

```solidity
function unpackTriggerOrder(uint256 _packed) external pure returns (uint8 orderType, address trader, uint32 index)
```

*Unpacks trigger order calldata into 3 values*

### Parameters

| Name     | Type    | Description  |
| -------- | ------- | ------------ |
| \_packed | uint256 | packed value |

### Return Values

| Name      | Type    | Description    |
| --------- | ------- | -------------- |
| orderType | uint8   | order type     |
| trader    | address | trader address |
| index     | uint32  | trade index    |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gains.trade/developer/technical-reference/contracts/libraries/packingutils.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
