# Invert bits binary

**URL:** https://discourse.nodered.org/t/invert-bits-binary/43226
**Category:** General
**Created:** [26 March 2021 08:06 UTC](https://discourse.nodered.org/t/invert-bits-binary/43226 "2021-03-26T08:06:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![raulrodca](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@raulrodca](https://discourse.nodered.org/u/raulrodca)
#### Post date: [26 March 2021 08:06 UTC](https://discourse.nodered.org/t/invert-bits-binary/43226/1 "2021-03-26T08:06:03Z")

</div>

hello good, I wanted to be able to change the order of the bits for their correct reading.  
When I want it to get a 1 in binary, it represents it to me in the following way

![Sin título](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/7/e7af8b1cc840d12633c0772076a4f600774bab55.jpeg)

What I wish is for it to be positioned correctly as follows.

0000000000000001

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [26 March 2021 08:10 UTC](https://discourse.nodered.org/t/invert-bits-binary/43226/2 "2021-03-26T08:10:28Z")

</div>

> [@raulrodca](#):
>
> What I wish is for it to be positioned correctly as follows.
> 
> 0000000000000001

What you have is correct. Bit 0 (array element [0]) is `1`

```auto
BIT 1 1
     5432109876543210
VAL 0000000000000001

```

If you must, then look at [array reverse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [26 March 2021 08:22 UTC](https://discourse.nodered.org/t/invert-bits-binary/43226/3 "2021-03-26T08:22:38Z")

</div>

Additionally, if you want it as a bit string, then call join("") on the array....

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/71ec8c5eb7179f5bfe02ce4ef01fd51afc9eec39.png)

↑ obviously that was reversed first.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/e/7e2ae093df7c830fdc95cef6d33bd1ec03049357.png)

---

<div class="post-metadata">

### Author: ![raulrodca](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@raulrodca](https://discourse.nodered.org/u/raulrodca)
#### Post date: [26 March 2021 08:26 UTC](https://discourse.nodered.org/t/invert-bits-binary/43226/4 "2021-03-26T08:26:59Z")

</div>

I got it in the following way. I have created a function to invert the bits

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/87c6c7474a5fee1865e0d0704bb0df6dc6429e09.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/19f9de1c439c82cae0520b1ad16946e9b9c0deec.png)

Thanks for your interest

---

<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: [9 April 2021 08:27 UTC](https://discourse.nodered.org/t/invert-bits-binary/43226/5 "2021-04-09T08:27:48Z")

</div>

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