---
schema_version: "1"
id: 014a2d68c829ffdc69bd4fecee48982265ada029b172fc3e3a4be0a00805c019
title: toBinary
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.12/dw-numbers-functions-tobinary.md
canonical_url: https://docs.mulesoft.com/dataweave/2.12/dw-numbers-functions-tobinary
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 29fcf46775bffd2ae47c19fdf2e919fa4a52d481efa404430696bb06663b75f3
description: MuleSoft Documentation Site
release: "2.12"
latest: false
---
---
product: DataWeave
version: 2.12
---

# toBinary

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## toBinary(number: Number): String

Transforms a decimal number into a binary number.

_Introduced in DataWeave version 2.2.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>number</code></p></td><td><p>The input number.</p></td></tr></tbody></table>

### Example

This example shows how the `toBinary` behaves with different inputs.

#### Source

```DataWeave
%dw 2.0
import toBinary from dw::core::Numbers
output application/json
---
{
    a: toBinary(-2),
    b: toBinary(100000000000000000000000000000000000000000000000000000000000000),
    c: toBinary(0),
    d: toBinary(null),
    e: toBinary(2),
}
```

#### Output

```JSON
{
  "a": "-10",
  "b": "11111000111010111010110100101011100001001110000011010101100010111101001011100000100010011000011101100101101001111101111010110010010100110010100100000000000000000000000000000000000000000000000000000000000000",
  "c": "0",
  "d": null,
  "e": "10"
}
```

## toBinary(number: Null): Null

Helper function that enables `toBinary` to work with null value.

_Introduced in DataWeave version 2.2.0._
