I would like to convert a hex number to decimal.
Asked
Active
Viewed 830 times
1
-
https://ethereum.stackexchange.com/questions/47472/integer-to-hexadecimal-number?rq=1 – Majd TL Nov 20 '21 at 08:37
-
Hi AmiraliSahraei! Welcome to Ethereum Stackexchange! What are you trying to achieve? What types are involved to do the conversion in solidity? – Ismael Nov 23 '21 at 16:52
1 Answers
-1
Here's how you can do it:
const { utils, BigNumber } = require("ethers);
const largeNumber = BigNumber.from(0x3eef
0f128b45c7eef) // write your hex number inside the bracket
console.log(largeNumber)
console.log(largeNumber.toString()) // if you want to see the bignumber.
You can now take it a step further by converting the bignumber (largeNumber) to decimal like so:
const toDecimal = utils.formatEther(largeNumber);
console.log(toDecimal)
Note Note that ethers version 6 beta has been throwing some errors. Instead, install ether version 5.7.2 - npm install ethers@5.7.4
Ololade
- 73
- 7
-
-
-
-
Run it in a solidity environment and see if it will run or throw an error. – Ololade Feb 17 '23 at 08:04
-