convert.js 395 B

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