From a27637888792eada3db2ac7625cc10cad3f1f0a9 Mon Sep 17 00:00:00 2001 From: Chris van Marle Date: Fri, 12 Oct 2018 10:00:09 +0200 Subject: [PATCH] Enable parsing of negative decimals #176 --- src/core/operations/FromDecimal.mjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/operations/FromDecimal.mjs b/src/core/operations/FromDecimal.mjs index f3c117ff..3376eebd 100644 --- a/src/core/operations/FromDecimal.mjs +++ b/src/core/operations/FromDecimal.mjs @@ -29,6 +29,11 @@ class FromDecimal extends Operation { "name": "Delimiter", "type": "option", "value": DELIM_OPTIONS + }, + { + "name": "Convert negatives", + "type": "boolean", + "value": false } ]; this.patterns = [ @@ -71,7 +76,11 @@ class FromDecimal extends Operation { * @returns {byteArray} */ run(input, args) { - return fromDecimal(input, args[0]); + let data = fromDecimal(input, args[0]); + if (args[1]) { // Convert negatives + data = data.map(v => v < 0 ? 0xFF + v + 1 : v); + } + return data; } }