# How use biguint64 in buffer.parser

**URL:** <https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688>\
**Category:** General\
**Created:** [10 November 2020 17:42 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688 "2020-11-10T17:42:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![thecoder](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@thecoder](https://discourse.nodered.org/u/thecoder)\
**Post date:** [10 November 2020 17:42 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688/1 "2020-11-10T17:42:38Z")

</div>

I need to parse a group of bits among 5 bytes, so, I need to use the format biguint64(be), however, I get an error.

"TypeError: Cannot read property 'bind' of undefined"

The group of interest is the following (in italic)

0101 _1001 11001010 01001010 10110011 111_ 01101 (plus two additional bytes)

I've inserted this mask and there is not option for scale

0xFFFFFFFE0000000

Is it better to use uint32(be) even the bits are among 5 bytes insted of 4 or less? Please, I need some help here. NOTE: I also tried uint32(be)

---

<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:** [10 November 2020 18:06 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688/2 "2020-11-10T18:06:18Z")

</div>

Biguint64 is problematic. The node-red debug cannot display them (thats why you get an error) OR your nodejs version is not new enough (no bigint support)

If you just want 5 bits spread out across 5 words, you could use BOOL or 16BIT then access the bits as bools or 0/1s

If you want to make a value from 5 bits across 5 bytes (most strange) them I would probably get 5 bytes and then use a function node to extract the bits and combine them into a number using masks and bit shifts.

---

<div class="post-metadata">

**Author:** ![thecoder](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@thecoder](https://discourse.nodered.org/u/thecoder)\
**Post date:** [10 November 2020 19:50 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688/3 "2020-11-10T19:50:14Z")

</div>

Can I use BOOL or 16BIT inside the same buffer parser node or I need to do it outside? I would like to accomplish it using the same node.

The first and last (fifth word are splitted in half, the three middle ones are full hex.

---

<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:** [10 November 2020 20:24 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688/4 "2020-11-10T20:24:54Z")

</div>

> [@thecoder](#):
>
> Can I use BOOL or 16BIT inside the same buffer parser node

Of course. Give it a go.

> [@thecoder](#):
>
> The first and last (fifth word are splitted in half, the three middle ones are full hex.

I can't understand this statement.

Perhaps if you can provide sample data and a specification there is a simple answer.

I would need sample input data, which bytes & bits to use, the final value to output.

---

<div class="post-metadata">

**Author:** ![thecoder](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@thecoder](https://discourse.nodered.org/u/thecoder)\
**Post date:** [10 November 2020 20:53 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688/5 "2020-11-10T20:53:36Z")

</div>

This is a string input

`return {"payload":{"link_type":"LINKTYPE_ETHERNET","pcap_header":{"tv_sec":1604796151,"tv_usec":651857,"caplen":141,"len":141},"payload":{"dhost":{"addr":[128,120,113,67,87,122]},"shost":{"addr":[8,0,39,206,160,222]},"ethertype":2048,"vlan":null,"payload":{"version":4,"headerLength":20,"diffserv":0,"length":127,"identification":39821,"flags":{"reserved":false,"doNotFragment":true,"moreFragments":false},"fragmentOffset":0,"ttl":64,"protocol":17,"headerChecksum":24686,"saddr":{"addr":[192,168,1,55]},"daddr":{"addr":[84,88,40,59]},"payload":{"sport":445,"dport":445,"length":107,"checksum":16111,"data":[255,255,255,255,255,255,8,0,39,206,160,222,137,71,17,0,26,1,32,80,0,128,0,45,1,0,0,0,8,0,39,206,160,222,167,132,17,153,25,84,8,250,206,69,32,241,1,240,7,204,0,0,0,0,7,209,0,0,2,2,0,0,0,224,148,21,0,89,202,74,179,237,146,185,39,0,0,0,0,0,48,212,30,0,225,31,192,250,126,191,233,237,7,55,254,235,255,246,0]}}}},"topic":"enp0s3","_msgid":"d4caea19.3a07d8","var1":255,"var2":250};`

The two variables missing are latitude and longitude with the following (the italic ones):

latitude  
|offset |Value DEC| Value BIN |  
|67|89|0101_1001_||||  
|68|202|_11001010_||||  
|69|74|_01001010_||||  
|70|179|_10110011_||||  
|71|237|_111_01101||

The resulting BIN 1001110010100100101010110011111

with output 1314018719

Longitude  
|offset |Value DEC| Value BIN |  
|71|237|111_01101_||  
|72|146|_10010010_||||  
|73|185|_10111001_||||  
|74|39|_00100111_||||  
|75|0|_000_00000||

The resulting BIN 01101100100101011100100100111000

The output 1821755704

---

<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:** [10 November 2020 22:37 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688/6 "2020-11-10T22:37:33Z")

</div>

Are you 100% certain the values you want are 2 values that start and end in the middle of a byte?  
also, Latitude has 31 bits and Longitude has 32 bits!?? I find this quite odd.

Latitude

```auto
byte 67 68 69 70 71                     
bin xxxx 1001 1100 1010 0100 1010 1011 0011 111x xxxx

```

Longitude

```auto
byte 71 72 73 74 75                     
bin xxx0 1101 1001 0010 1011 1001 0010 0111 000x xxxx

```

---

<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:** [10 November 2020 22:43 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688/7 "2020-11-10T22:43:55Z")

</div>

Where is this data coming from?

Do you have control over its format or is the incoming data format locked / proprietary?

If you have any control whatsoever, I would strongly recommend the following (in order of best to "a bit better")

1. If you can send data in JSON format with "actual values" (instead of bytes) - none of this would be necessary
2. If you can send or get data in XML format with "actual values" (instead of bytes) - none of this would be necessary
3. If you can send or get data in a CSV or TSV format - much of this would not be necessary
4. If the data is from a PLC, please byte align (and pad where necessary to achieve byte alignment)
5. If the data is coming from a program that can only transmit bytes & you have access to source, again, please re-align the bytes.

---

<div class="post-metadata">

**Author:** ![thecoder](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@thecoder](https://discourse.nodered.org/u/thecoder)\
**Post date:** [10 November 2020 23:02 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688/8 "2020-11-10T23:02:09Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a8853d59c0b20e17eaa1f5153ed91963402a0ad1.png)

The source is open following ASN.1 UPER format. I cannot control the bit position. Is it possible to send, for instance, the latitude split in two integers and merge them in a function node?

---

<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:** [10 November 2020 23:21 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688/9 "2020-11-10T23:21:29Z")

</div>

> [@thecoder](#):
>
> Is it possible to send, for instance, the latitude split in two integers and merge them in a function node?

Of course...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/03f636e34101f546d906c0cedfd5ecb13017385b.png)

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

```auto
// byte 67 68 69 70 71
// bin xxxx 1001 1100 1010 0100 1010 1011 0011 111x xxxx
// mask 0 F F F F F F F E 0
// 1314018719
msg.payload.Lattiude = (msg.payload.LatHi << 3) + (msg.payload.LatLo >> 5)

// byte 71 72 73 74 75                     
// bin xxx0 1101 1001 0010 1011 1001 0010 0111 000x xxxx
// mask 1 F F F F F F F E 0
// 1821755704
msg.payload.Longitude = (msg.payload.LonHi << 3) + (msg.payload.LonLo >> 5)
return msg;

```

```auto
[{"id":"31ef54c0.333eec","type":"inject","z":"e39accec.112de","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[255,255,255,255,255,255,8,0,39,206,160,222,137,71,17,0,26,1,32,80,0,128,0,45,1,0,0,0,8,0,39,206,160,222,167,132,17,153,25,84,8,250,206,69,32,241,1,240,7,204,0,0,0,0,7,209,0,0,2,2,0,0,0,224,148,21,0,89,202,74,179,237,146,185,39,0,0,0,0,0,48,212,30,0,225,31,192,250,126,191,233,237,7,55,254,235,255,246,0]","payloadType":"bin","x":850,"y":60,"wires":[["c37385ab.059b58"]]},{"id":"c37385ab.059b58","type":"buffer-parser","z":"e39accec.112de","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint32be","name":"LatHi","offset":67,"length":1,"offsetbit":0,"scale":1,"mask":"0x0FFFFFFF"},{"type":"uint8","name":"LatLo","offset":71,"length":1,"offsetbit":0,"scale":1,"mask":"0xE0"},{"type":"uint32be","name":"LonHi","offset":71,"length":1,"offsetbit":0,"scale":1,"mask":"0x1FFFFFFF"},{"type":"uint8","name":"LonLo","offset":75,"length":1,"offsetbit":0,"scale":1,"mask":"0xE0"}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":true,"x":1020,"y":60,"wires":[["5774845e.9d79fc"]]},{"id":"5774845e.9d79fc","type":"function","z":"e39accec.112de","name":"","func":"\n// byte 67 68 69 70 71\n// bin xxxx 1001 1100 1010 0100 1010 1011 0011 111x xxxx\n// mask 0 F F F F F F F E 0\n// 1314018719\nmsg.payload.Lattiude = (msg.payload.LatHi << 3) + (msg.payload.LatLo >> 5)\n\n// byte 71 72 73 74 75 \n// bin xxx0 1101 1001 0010 1011 1001 0010 0111 000x xxxx\n// mask 1 F F F F F F F E 0\n// 1821755704\nmsg.payload.Longitude = (msg.payload.LonHi << 3) + (msg.payload.LonLo >> 5)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":120,"wires":[["441864a.e7bd49c"]]},{"id":"441864a.e7bd49c","type":"debug","z":"e39accec.112de","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1040,"y":120,"wires":[]}]

```

---

<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:** [24 November 2020 23:21 UTC](https://discourse.nodered.org/t/how-use-biguint64-in-buffer-parser/35688/10 "2020-11-24T23:21:30Z")

</div>

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