Advertisement
viligen

hex

Jun 12th, 2022
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Hex {
  2.     constructor(num) {
  3.         this.value = num;
  4.     }
  5.     valueOf() {
  6.         return this.value;
  7.     }
  8.     toString() {
  9.         return '0x' + this.value.toString(16).toUpperCase();
  10.     }
  11.     plus(newObjorNum) {
  12.         if (typeof newObjorNum === 'number') {
  13.             return new Hex(newObjorNum + this.value);
  14.         }
  15.         return new Hex(newObjorNum.valueOf() + this.value);
  16.     }
  17.     minus(newObjorNum) {
  18.         if (typeof newObjorNum === 'number') {
  19.             return new Hex(this.value - newObjorNum);
  20.         }
  21.         return new Hex(this.value - newObjorNum.valueOf());
  22.     }
  23.     parse(str) {
  24.         return parseInt(str, 16);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement