# Convert DINT to BOOLEAN showing 1's and 0's

**URL:** <https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848>\
**Category:** Ignition\
**Created:** [February 16, 2024, 4:22pm UTC](https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848 "2024-02-16T16:22:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 16, 2024, 4:22pm UTC](https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848/1 "2024-02-16T16:22:32Z")

</div>

I have a DINT tag being read in from an OPC source. What I want to do is to take the DINT and actually show the full 32 bits as 1's and 0's. I have a UDT set up for the tag. First question is would it be better to create another tag within the UDT that converts it from a DINT to BOOL array or have a label object which takes the tag in and converts it via an expression. Second question is whats the best way to do it? Would it be reading in the DINT and then creating a FOR loop which advances through each bit in the DINT and then concatenates it into a string for example?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 16, 2024, 4:23pm UTC](https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848/2 "2024-02-16T16:23:33Z")

</div>

Show it where?

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 16, 2024, 4:24pm UTC](https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848/3 "2024-02-16T16:24:25Z")

</div>

I want to show it on a vision screen. I am replicating a screen from an HMI and they use the DINT to show 1's and 0's from the value of the DINT

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 16, 2024, 4:27pm UTC](https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848/4 "2024-02-16T16:27:18Z")

</div>

There's a `toBinary` expression that should make this pretty trivial.

> **[toBinary | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/string/toBinary)**
>
> Returns a binary formatted string representing the unsigned integer argument.

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 16, 2024, 7:00pm UTC](https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848/5 "2024-02-16T19:00:46Z")

</div>

Thanks. I figured there was a function to do this already. Only thing I ran into was having 0 show up when the value was zero instead of 32 0's.

To test I did the following and worked great.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/8/48449b974863b9fb07e9c6666d284f36c21683bc.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/4/349c3872fbf4f50137739185d8a657599bd96771.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 16, 2024, 7:51pm UTC](https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848/6 "2024-02-16T19:51:18Z")

</div>

You can use `stringFormat` to do the padding as well, so you only have a single operation:

> **[stringFormat | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/string/stringFormat)**
>
> This expression returns a formatted string using the specified format string and arguments. Mainly, this expression is used for building dynamic string objects.

So `stringFormat(toBinary({tag}), "%032d")` or maybe just `"%32d"`.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 16, 2024, 7:52pm UTC](https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848/7 "2024-02-16T19:52:11Z")

</div>

stringFormat should lighten the load, and maybe look a bit cleaner.

```auto
stringFormat('%032d %032d %032d', 
             toInt(toBinary({[RTP_Hertwitch]SAW/GL_ScrapLt_scrapPattern_TEST})),
             toInt(toBinary({[RTP_Hertwitch]SAW/GL_ScrapLt_scrapPattern_TEST1})),
             toInt(toBinary({[RTP_Hertwitch]SAW/GL_ScrapLt_scrapPattern_TEST2}))
            )

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 16, 2024, 7:52pm UTC](https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848/8 "2024-02-16T19:52:33Z")

</div>

Post code, man, not pictures of code! Post code!  
See [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). It means we can copy and use it or edit it in our replies. Thanks!

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 16, 2024, 8:57pm UTC](https://forum.inductiveautomation.com/t/convert-dint-to-boolean-showing-1s-and-0s/85848/9 "2024-02-16T20:57:32Z")

</div>

Haha this is true. Will do next time.
