> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/binarydecode.md).

# BinaryDecode

Encodes binary data to a string with the specified algorithm

## Method Signature

```
BinaryDecode(string=[string], encoding=[string])
```

### Arguments

| Argument   | Type     | Required | Description                                                                                         | Default |
| ---------- | -------- | -------- | --------------------------------------------------------------------------------------------------- | ------- |
| `string`   | `string` | `true`   | The string to decode that has binary encoded data                                                   |         |
| `encoding` | `string` | `true`   | The encoding type to use for decoding the binary data. Valid values are: Hex, UU, Base64, Base64Url |         |

## Examples

### Decode a string using hex back into binary encoding of the string

use binaryDecode to decode with hex

[Run Example](https://try.boxlang.io/?code=eJxLysxLLKp0SU3OT0nVUFByMzNyUtJRUMpIrVBS0LTmAgCgUAip)

```java
binaryDecode( "F62B", "hex" );

```

Result: \[B\@1a0d6c79

### Decode a string using UNIX UUencode (UU) back into binary encoding of the string

use binaryDecode to decode with UNIX UUencode (UU)

[Run Example](https://try.boxlang.io/?code=eJxLysxLLKp0SU3OT0nVUFBSswk3DLIyi3RX0lFQCg1VUtC05gIAxowJag%3D%3D)

```java
binaryDecode( "&<W1R:6YG", "UU" );

```

Result: \[B\@20fe6ce1

### Decode a string using base64 back into binary encoding of the string

use binaryDecode to decode with base64

[Run Example](https://try.boxlang.io/?code=eJxLysxLLKp0SU3OT0nVUFAKNQ6qTAw3zVPSUVBKSixONTNRUtC05gIA9ccLJw%3D%3D)

```java
binaryDecode( "U3RyaW5n", "base64" );

```

Result: \[B\@2a0e22fa

### Create a byte array with 16 bytes

Each byte in the array is set to 0

[Run Example](https://try.boxlang.io/?code=eJxLLCpKrPRJzdNQSMrMSyyqdElNzk9J1VBQMiAAlHQUlDJSK5QUNBU0rbkA1%2FwRiA%3D%3D)

```java
arrayLen( binaryDecode( "00000000000000000000000000000000", "hex" ) );

```

Result: 16

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJxLSixOjTczUbBVCMl3ArLNTDQUlDwVEnMVEhWKS4oy89L1lBQ0rbmSMvMSiyrjUxJLEiFqwXwNhSSofqCS1Lzk%2FJTUlHiIUqAqiBpXsDBQJcIEHQWljNQKsLkppbkFGlCVLqkQlagGwRWDlAMAIkc3%2Fg%3D%3D)

```java
base_64 = ToBase64( "I am a string." );
binary_data = ToBinary( base_64 );
encoded_binary = BinaryEncode( binary_data, "hex" );
dump( BinaryDecode( encoded_binary, "hex" ) );

```

## Related

* [BinaryEncode](/boxlang-language/reference/built-in-functions/binary/binaryencode.md)
* [BitAnd](/boxlang-language/reference/built-in-functions/binary/bitand.md)
* [BitMaskClear](/boxlang-language/reference/built-in-functions/binary/bitmaskclear.md)
* [BitMaskRead](/boxlang-language/reference/built-in-functions/binary/bitmaskread.md)
* [BitMaskSet](/boxlang-language/reference/built-in-functions/binary/bitmaskset.md)
* [BitNot](/boxlang-language/reference/built-in-functions/binary/bitnot.md)
* [BitOr](/boxlang-language/reference/built-in-functions/binary/bitor.md)
* [BitSh](/boxlang-language/reference/built-in-functions/binary/bitsh.md)
* [bitShln](/boxlang-language/reference/built-in-functions/binary/bitshln.md)
* [bitShrn](/boxlang-language/reference/built-in-functions/binary/bitshrn.md)
* [BitXor](/boxlang-language/reference/built-in-functions/binary/bitxor.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/binarydecode.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
