georgiev955

7-hex

Oct 9th, 2023
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Hex {
  2.     constructor(value) {
  3.         this.value = value;
  4.     }
  5.  
  6.     valueOf() {
  7.         return this.value;
  8.     }
  9.  
  10.     toString() {
  11.         return `0x${this.value.toString(16).toUpperCase()}`;
  12.     }
  13.  
  14.     plus(input) {
  15.         if (typeof input === 'object') {
  16.             let result = this.value + input.value;
  17.             return new Hex(result);
  18.         } else {
  19.             let result = this.value + input;
  20.             return new Hex(result);
  21.         }
  22.     }
  23.  
  24.     minus(input) {
  25.         if (typeof input === 'object') {
  26.             let result = this.value - input.value;
  27.             return new Hex(result);
  28.         } else {
  29.             let result = this.value - input;
  30.             return new Hex(result);
  31.         }
  32.     }
  33.  
  34.     parse(hexa) {
  35.         return hexa.toString(10);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment