فهرست منبع

Enable parsing of negative decimals #176

Chris van Marle 6 سال پیش
والد
کامیت
a276378887
1فایلهای تغییر یافته به همراه10 افزوده شده و 1 حذف شده
  1. 10 1
      src/core/operations/FromDecimal.mjs

+ 10 - 1
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;
     }
 
 }