# Convert hex to bin preserving long format

**URL:** <https://discourse.nodered.org/t/convert-hex-to-bin-preserving-long-format/54928>\
**Category:** General\
**Created:** [9 December 2021 12:59 UTC](https://discourse.nodered.org/t/convert-hex-to-bin-preserving-long-format/54928 "2021-12-09T12:59:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheMiloNet](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@TheMiloNet](https://discourse.nodered.org/u/TheMiloNet)\
**Post date:** [9 December 2021 12:59 UTC](https://discourse.nodered.org/t/convert-hex-to-bin-preserving-long-format/54928/1 "2021-12-09T12:59:39Z")

</div>

Hi all, i need to convert hex value eg "24" to bin. "00100100".  
Using the msg.payload = parseInt(msg.payload,16).toString(2) the result is "100100".  
How can obtain a long format value with all 8 bit "00100100"?

Best regards!

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [9 December 2021 13:19 UTC](https://discourse.nodered.org/t/convert-hex-to-bin-preserving-long-format/54928/2 "2021-12-09T13:19:47Z")

</div>

try appending the `.padStart(8, '0')` method

> **[String.prototype.padStart() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)**
>
> The padStart() method pads the
> current string with another string (multiple times, if needed) until the resulting
> string reaches the given length. The padding is applied from the start of the
> current string.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 December 2021 19:21 UTC](https://discourse.nodered.org/t/convert-hex-to-bin-preserving-long-format/54928/4 "2021-12-23T19:21:30Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
