# XOR and ADD of the buffer numbers

**URL:** https://discourse.nodered.org/t/xor-and-add-of-the-buffer-numbers/58547
**Category:** General
**Created:** [17 February 2022 17:16 UTC](https://discourse.nodered.org/t/xor-and-add-of-the-buffer-numbers/58547 "2022-02-17T17:16:15Z")
**Posts on this page:** 4
**Page:** 2

<div class="post-metadata">

### Author: ![alda](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@alda](https://discourse.nodered.org/u/alda)
#### Post date: [18 February 2022 14:32 UTC](https://discourse.nodered.org/t/xor-and-add-of-the-buffer-numbers/58547/21 "2022-02-18T14:32:48Z")

</div>

I found one more small problem. Main unit isn't accepting when I wll send a object and I must transform back to buffer. ☹  
But I hope buffer maker will help  
maybe better way is not transfer buffer to bject, but stay with buffer

---

<div class="post-metadata">

### Author: ![alda](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@alda](https://discourse.nodered.org/u/alda)
#### Post date: [18 February 2022 15:29 UTC](https://discourse.nodered.org/t/xor-and-add-of-the-buffer-numbers/58547/22 "2022-02-18T15:29:27Z")

</div>

back to my first question. I reworked it to work with buffer.  
Is it possible rework this :

```auto
const data = Object.entries(msg.payload);

let ADDS = 0;
let XORS = 0;
for (let index = 0; index < data.length; index++) {
    const item = data[index][0];
    const value = data[index][1];
    if (item === "ADDS") continue; //skip ADDS prop
    if (item === "XORS") continue; //skip XORS prop
    if (item === "END") continue; //skip END prop
    ADDS += value;
    XORS ^= value;
}
msg.payload.ADDS = (ADDS ^ 0xAA) & 0xFF;
msg.payload.XORS = (XORS ^ 0xAA) & 0xFF;

return msg;

```

to work with this buffer ?:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b53ac2eff27013ec8b0e5581bb76a87275f9f31e.png)

I tried this, but result isn't ok:

```auto
let ADDS = 0;
let XORS = 0;
for (let index = 0; index < 15; index++) {
    const value = msg.payload.readUInt8(index);
    ADDS += value;
    XORS ^= value;
}
ADDS = (ADDS ^ 0xAA) & 0xFF;
XORS = (XORS ^ 0xAA) & 0xFF;
msg.payload.writeUInt8(ADDS,12)
msg.payload.writeUInt8(XORS,13)
return msg;

```

---

<div class="post-metadata">

### Author: ![alda](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@alda](https://discourse.nodered.org/u/alda)
#### Post date: [18 February 2022 16:07 UTC](https://discourse.nodered.org/t/xor-and-add-of-the-buffer-numbers/58547/23 "2022-02-18T16:07:36Z")

</div>

I got it, problem is buffer length. Not 15 but only 13 🙂

---

<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: [19 April 2022 16:08 UTC](https://discourse.nodered.org/t/xor-and-add-of-the-buffer-numbers/58547/24 "2022-04-19T16:08:24Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/xor-and-add-of-the-buffer-numbers/58547.md?page=1)
