Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Hex {
- constructor(value) {
- this.value = value;
- }
- valueOf() {
- return this.value;
- }
- toString() {
- return `0x${this.value.toString(16).toUpperCase()}`;
- }
- plus(input) {
- if (typeof input === 'object') {
- let result = this.value + input.value;
- return new Hex(result);
- } else {
- let result = this.value + input;
- return new Hex(result);
- }
- }
- minus(input) {
- if (typeof input === 'object') {
- let result = this.value - input.value;
- return new Hex(result);
- } else {
- let result = this.value - input;
- return new Hex(result);
- }
- }
- parse(hexa) {
- return hexa.toString(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment