2018-05-07 13:12:58 +02:00
|
|
|
/**
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-07-09 13:23:59 +02:00
|
|
|
import Operation from "../Operation.mjs";
|
2018-05-07 13:12:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bit shift left operation
|
|
|
|
*/
|
|
|
|
class BitShiftLeft extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BitShiftLeft constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Bit shift left";
|
|
|
|
this.module = "Default";
|
|
|
|
this.description = "Shifts the bits in each byte towards the left by the specified amount.";
|
2018-08-21 20:07:13 +02:00
|
|
|
this.infoURL = "https://wikipedia.org/wiki/Bitwise_operation#Bit_shifts";
|
2019-07-29 18:09:46 +02:00
|
|
|
this.inputType = "ArrayBuffer";
|
|
|
|
this.outputType = "ArrayBuffer";
|
2018-05-07 13:12:58 +02:00
|
|
|
this.args = [
|
|
|
|
{
|
|
|
|
"name": "Amount",
|
|
|
|
"type": "number",
|
|
|
|
"value": 1
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-29 18:09:46 +02:00
|
|
|
* @param {ArrayBuffer} input
|
2018-05-07 13:12:58 +02:00
|
|
|
* @param {Object[]} args
|
2019-07-29 18:09:46 +02:00
|
|
|
* @returns {ArrayBuffer}
|
2018-05-07 13:12:58 +02:00
|
|
|
*/
|
|
|
|
run(input, args) {
|
|
|
|
const amount = args[0];
|
2019-07-29 18:09:46 +02:00
|
|
|
input = new Uint8Array(input);
|
2018-05-07 13:12:58 +02:00
|
|
|
|
|
|
|
return input.map(b => {
|
|
|
|
return (b << amount) & 0xff;
|
2019-07-29 18:09:46 +02:00
|
|
|
}).buffer;
|
2018-05-07 13:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Highlight Bit shift left
|
|
|
|
*
|
|
|
|
* @param {Object[]} pos
|
|
|
|
* @param {number} pos[].start
|
|
|
|
* @param {number} pos[].end
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {Object[]} pos
|
|
|
|
*/
|
|
|
|
highlight(pos, args) {
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Highlight Bit shift left in reverse
|
|
|
|
*
|
|
|
|
* @param {Object[]} pos
|
|
|
|
* @param {number} pos[].start
|
|
|
|
* @param {number} pos[].end
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {Object[]} pos
|
|
|
|
*/
|
|
|
|
highlightReverse(pos, args) {
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BitShiftLeft;
|