简体   繁体   中英

How to Convert byte32/hex to number in web3?

I need to Convert byte32/hex to number in web3. I want to Convert hashbyte32/hex to number in web3.

You can convert the hex bytes32 value to its decimal representation using the web3.eth.abi.decodeParameter() function ( docs ).

// hex representation of the 32-byte hash
const hash = "0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6";
// returns its decimal representation: 90743482286830539503240959006302832933333810038750515972785732718729991261126
const decimal = web3.eth.abi.decodeParameter("uint256", hash);

However, hashing is a one-way function, so it's not possible by design to get the original value (before hashing) from the hash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM