# Unpacking hexadecimal numbers

**URL:** https://discourse.nodered.org/t/unpacking-hexadecimal-numbers/93559
**Category:** General
**Created:** [29 November 2024 05:49 UTC](https://discourse.nodered.org/t/unpacking-hexadecimal-numbers/93559 "2024-11-29T05:49:23Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![redhead](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@redhead](https://discourse.nodered.org/u/redhead)
#### Post date: [29 November 2024 05:49 UTC](https://discourse.nodered.org/t/unpacking-hexadecimal-numbers/93559/1 "2024-11-29T05:49:23Z")

</div>

The serial device sends json data in the following hexadecimal format:  
0: 0xca  
1: 0x09  
2: 0x06  
3: 0x02  
4: 0x37  
5: 0x01  
6: 0x00  
7: 0x00  
8: 0x65  
9: 0x00  
10: 0x10  
11: 0x06  
12: 0xd2  
13: 0x35  
I need to combined indexes 10 and 11 to unpack the hexadecimal number. For example, index 9 = 0x10 and index 10 = 0x06, therefore the unpacked hexadecimal number is 0610. How would I do this in Node-RED?

---

<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: [29 November 2024 06:00 UTC](https://discourse.nodered.org/t/unpacking-hexadecimal-numbers/93559/2 "2024-11-29T06:00:34Z")

</div>

[node-red-contrib-buffer-parser (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-buffer-parser) can do pretty much anything you need. There are built in example flows and built in help. Lastly if you search this forum for buffer parser the are lots of threads with detailed usage examples.

---

<div class="post-metadata">

### Author: ![redhead](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@redhead](https://discourse.nodered.org/u/redhead)
#### Post date: [2 December 2024 17:41 UTC](https://discourse.nodered.org/t/unpacking-hexadecimal-numbers/93559/3 "2024-12-02T17:41:48Z")

</div>

Thanks for point me in the right direction. I got it to work for me.  
Is there a way to bit unpack (go from hexadecimal to binary)? For example, Buffer index 10 is the device's capabilities or attributes which is sent as a hexadecimal number. Each bit which makes up the hexadecimal number, represents the device's multiple attributes.

---

<div class="post-metadata">

### Author: ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)
#### Post date: [2 December 2024 18:10 UTC](https://discourse.nodered.org/t/unpacking-hexadecimal-numbers/93559/4 "2024-12-02T18:10:57Z")

</div>

[node-red-contrib-bitunloader](https://flows.nodered.org/node/node-red-contrib-bitunloader) can handle unpacking from numbers to bits in a couple different formats, like bit arrays or an object of bools, etc depending on how you want to process them later down the flow. It does only work with decimal numbers though.

---

<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: [3 December 2024 22:53 UTC](https://discourse.nodered.org/t/unpacking-hexadecimal-numbers/93559/5 "2024-12-03T22:53:54Z")

</div>

Since you didn't reply to my response I didn't get a notification.

If you read the built in help for buffer parser you will see there is both bit types (for simply extracting bits) and there are masking and equations (for numbers i.e to get bit 7 of a single byte you could use mask `0x80` and equation `=0x80`

---

<div class="post-metadata">

### Author: ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)
#### Post date: [4 December 2024 16:32 UTC](https://discourse.nodered.org/t/unpacking-hexadecimal-numbers/93559/6 "2024-12-04T16:32:46Z")

</div>

```auto
let hexString = "1A"; 
// Hexadezimale Zahl als String 
let decimalNumber = parseInt(hexString, 16);
 // Umwandlung in Dezimalzahl 
console.log(decimalNumber); 
// Ausgabe: 26

```

---

<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: [4 March 2025 16:33 UTC](https://discourse.nodered.org/t/unpacking-hexadecimal-numbers/93559/7 "2025-03-04T16:33:21Z")

</div>

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