# Add support for numeric literals - binary (prefix 0b), octal (prefix 0o) and hexadecimal (prefix: 0x)

**URL:** <https://discourse.nodered.org/t/add-support-for-numeric-literals-binary-prefix-0b-octal-prefix-0o-and-hexadecimal-prefix-0x/54148>\
**Category:** Feature Requests\
**Created:** [23 November 2021 08:47 UTC](https://discourse.nodered.org/t/add-support-for-numeric-literals-binary-prefix-0b-octal-prefix-0o-and-hexadecimal-prefix-0x/54148 "2021-11-23T08:47:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stas-mursaev](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stas-mursaev/32/51459_2.png) [@stas-mursaev](https://discourse.nodered.org/u/stas-mursaev)\
**Post date:** [23 November 2021 08:47 UTC](https://discourse.nodered.org/t/add-support-for-numeric-literals-binary-prefix-0b-octal-prefix-0o-and-hexadecimal-prefix-0x/54148/1 "2021-11-23T08:47:50Z")

</div>

Hi all,

See [Numeric Literals spec](https://262.ecma-international.org/6.0/#sec-literals-numeric-literals)

```auto
var bin = 0b1111;
var oct = 0o17;
var hex = 0xF;

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [23 November 2021 09:03 UTC](https://discourse.nodered.org/t/add-support-for-numeric-literals-binary-prefix-0b-octal-prefix-0o-and-hexadecimal-prefix-0x/54148/2 "2021-11-23T09:03:04Z")

</div>

where is that not supported ?

---

<div class="post-metadata">

**Author:** ![stas-mursaev](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stas-mursaev/32/51459_2.png) [@stas-mursaev](https://discourse.nodered.org/u/stas-mursaev)\
**Post date:** [23 November 2021 09:41 UTC](https://discourse.nodered.org/t/add-support-for-numeric-literals-binary-prefix-0b-octal-prefix-0o-and-hexadecimal-prefix-0x/54148/3 "2021-11-23T09:41:18Z")

</div>

I have a RPi3/Raspbian & run a docker image with Node-RED 2.1.3, and set up some interactions with Zelio Logic through Modbus TCP

When I create an Inject node, adding msg.payload = any ordinary input like (numeric)1 does not fire a red error frame around an input field but (numeric)0b0000000000000001 does (and also a warning on Deploy - "The workspace contains some nodes that are not properly configured")

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [23 November 2021 09:49 UTC](https://discourse.nodered.org/t/add-support-for-numeric-literals-binary-prefix-0b-octal-prefix-0o-and-hexadecimal-prefix-0x/54148/4 "2021-11-23T09:49:09Z")

</div>

Ah right the inject node - ok. Makes sense. Not sure how easy it would be to do generically for all numeric input type fields - would need some thought.  
(works fine in a function node of course)

---

<div class="post-metadata">

**Author:** ![stas-mursaev](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stas-mursaev/32/51459_2.png) [@stas-mursaev](https://discourse.nodered.org/u/stas-mursaev)\
**Post date:** [23 November 2021 10:07 UTC](https://discourse.nodered.org/t/add-support-for-numeric-literals-binary-prefix-0b-octal-prefix-0o-and-hexadecimal-prefix-0x/54148/5 "2021-11-23T10:07:24Z")

</div>

This also works despite warnings in the inject node too but not in every node with numeric input I have tried

For ex., when I added a Change node with a Rule  
Set msg.payload to the value (expression) payload.arr[1] & 32768 - it works fine, but with payload.arr[1] & 0b1000000000000000 it does not work after deployment with an error "Invalid JSONata expression: Syntax error: "b1000000000000000""

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [23 November 2021 10:25 UTC](https://discourse.nodered.org/t/add-support-for-numeric-literals-binary-prefix-0b-octal-prefix-0o-and-hexadecimal-prefix-0x/54148/6 "2021-11-23T10:25:03Z")

</div>

We could add support for non-decimal base representations in our standard TypedInput widget for the 'number' type - as used by the Inject node and in other places.

There would be a risk that a contrib node uses that widget without using the underlying utility we provide for interpreting the value because they assume it is a number that can be parsed with the standard JavaScript functions `parseFloat` or `parseInt`. A quick test shows those functions don't handle binary/octal/hex representations (with one exception - `parseInt("0x10")` does work, but that's it.

As for the JSONata mode - we can only support what JSONata itself supports. Given JSON does not support hex or octal number representations, then it is unlike that JSONata would add support for anything else.

---

<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:** [22 January 2022 10:26 UTC](https://discourse.nodered.org/t/add-support-for-numeric-literals-binary-prefix-0b-octal-prefix-0o-and-hexadecimal-prefix-0x/54148/7 "2022-01-22T10:26:00Z")

</div>

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