BitShiftLeft.mjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * @author n1474335 [n1474335@gmail.com]
  3. * @copyright Crown Copyright 2016
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation.mjs";
  7. /**
  8. * Bit shift left operation
  9. */
  10. class BitShiftLeft extends Operation {
  11. /**
  12. * BitShiftLeft constructor
  13. */
  14. constructor() {
  15. super();
  16. this.name = "Bit shift left";
  17. this.module = "Default";
  18. this.description = "Shifts the bits in each byte towards the left by the specified amount.";
  19. this.infoURL = "https://wikipedia.org/wiki/Bitwise_operation#Bit_shifts";
  20. this.inputType = "ArrayBuffer";
  21. this.outputType = "ArrayBuffer";
  22. this.args = [
  23. {
  24. "name": "Amount",
  25. "type": "number",
  26. "value": 1
  27. }
  28. ];
  29. }
  30. /**
  31. * @param {ArrayBuffer} input
  32. * @param {Object[]} args
  33. * @returns {ArrayBuffer}
  34. */
  35. run(input, args) {
  36. const amount = args[0];
  37. input = new Uint8Array(input);
  38. return input.map(b => {
  39. return (b << amount) & 0xff;
  40. }).buffer;
  41. }
  42. /**
  43. * Highlight Bit shift left
  44. *
  45. * @param {Object[]} pos
  46. * @param {number} pos[].start
  47. * @param {number} pos[].end
  48. * @param {Object[]} args
  49. * @returns {Object[]} pos
  50. */
  51. highlight(pos, args) {
  52. return pos;
  53. }
  54. /**
  55. * Highlight Bit shift left in reverse
  56. *
  57. * @param {Object[]} pos
  58. * @param {number} pos[].start
  59. * @param {number} pos[].end
  60. * @param {Object[]} args
  61. * @returns {Object[]} pos
  62. */
  63. highlightReverse(pos, args) {
  64. return pos;
  65. }
  66. }
  67. export default BitShiftLeft;