Skip to content

Commit

Permalink
Enable parsing of negative decimals gchq#176
Browse files Browse the repository at this point in the history
  • Loading branch information
qistoph committed Oct 12, 2018
1 parent d6c6981 commit a276378
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/core/operations/FromDecimal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class FromDecimal extends Operation {
"name": "Delimiter",
"type": "option",
"value": DELIM_OPTIONS
},
{
"name": "Convert negatives",
"type": "boolean",
"value": false
}
];
this.patterns = [
Expand Down Expand Up @@ -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;
}

}
Expand Down

0 comments on commit a276378

Please sign in to comment.