# BinaryEncode

Encodes binary data to a string with the specified algorithm

## Method Signature

```
BinaryEncode(binary=[any], encoding=[string])
```

### Arguments

| Argument   | Type     | Required | Description               | Default |
| ---------- | -------- | -------- | ------------------------- | ------- |
| `binary`   | `any`    | `true`   | The binary data to encode |         |
| `encoding` | `string` | `true`   | The encoding to use       |         |

## Examples

### Encode a binary string back to a string using hex

use binaryEncode to Encode with hex

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

```java
s = binaryDecode( "737472696E67", "hex" );
binaryEncode( s, "hex" );

```

Result: 737472696e67

### Encode a binary using UNIX UUencode (UU) back into string

use binaryEncode to Encode with UNIX UUencode (UU)

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

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

```

Result: W1R6YA==

### Encode a binary using base64 back into a string

use binaryEncode to Encode with base64

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

```java
s = binaryDecode( "&<W1R:6YG", "base64" );
binaryEncode( s, "base64" );

```

Result: W1R6YA==

### Additional Examples

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

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

```

## Related

* [BinaryDecode](/boxlang-language/reference/built-in-functions/binary/binarydecode.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: 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/binaryencode.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.
