From e2f369fb4d862959aae9465de2e6b5b7406711c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20K=C3=B6ritz?= Date: Sat, 4 Jul 2020 21:25:48 +0200 Subject: [PATCH] Added the ability to do circular left shifts --- src/core/operations/BitShiftLeft.mjs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/operations/BitShiftLeft.mjs b/src/core/operations/BitShiftLeft.mjs index cd9f4568..b8aaae71 100644 --- a/src/core/operations/BitShiftLeft.mjs +++ b/src/core/operations/BitShiftLeft.mjs @@ -28,6 +28,11 @@ class BitShiftLeft extends Operation { "name": "Amount", "type": "number", "value": 1 + }, + { + "name": "Circular", + "type": "boolean", + "value": false } ]; } @@ -38,12 +43,20 @@ class BitShiftLeft extends Operation { * @returns {ArrayBuffer} */ run(input, args) { - const amount = args[0]; + const amount = args[0], + circular = args[1]; + input = new Uint8Array(input); - return input.map(b => { - return (b << amount) & 0xff; - }).buffer; + if (circular) { + return input.map(b => { + return (b << amount) | b >> (8 - amount); + }).buffer; + } else { + return input.map(b => { + return (b << amount) & 0xff; + }).buffer; + } } /**