# 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](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/binaryencode)
* [BitAnd](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/bitand)
* [BitMaskClear](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/bitmaskclear)
* [BitMaskRead](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/bitmaskread)
* [BitMaskSet](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/bitmaskset)
* [BitNot](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/bitnot)
* [BitOr](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/bitor)
* [BitSh](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/bitsh)
* [bitShln](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/bitshln)
* [bitShrn](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/bitshrn)
* [BitXor](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/bitxor)


---

# 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://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/binary/binarydecode.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.
