convert.js 374 B

12345678910111213141516
  1. "use strict";
  2. function fromDecimalToHex(number) {
  3. if (typeof number !== 'number') throw 'The input provided should be a number';
  4. return `0x${number.toString(16)}`;
  5. }
  6. function fromHexToDecimal(hex) {
  7. if (typeof hex !== 'string') throw 'The input provided should be a string';
  8. return parseInt(hex, 16);
  9. }
  10. module.exports = {
  11. fromDecimalToHex,
  12. fromHexToDecimal
  13. };