1

Sir, If my uint is 10,how to convert 10 to '0x000000000000000000000000000000000000000000000000000000000000000a' by using Node.js? and reverse it from '0x000000000000000000000000000000000000000000000000000000000000000a' to uint 10 ?

closed as off-topic by Richard Horrocks, Nicolas Massart, shane, Achala Dissanayake, Mahesh Rajput Jun 12 at 4:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Ethereum, the decentralized application platform and smart contract enabled blockchain, within the scope defined in the help center." – Richard Horrocks, Nicolas Massart, shane, Achala Dissanayake, Mahesh Rajput
If this question can be reworded to fit the rules in the help center, please edit the question.

1

Sir, If my uint is 10,how to convert 10 to '0x000000000000000000000000000000000000000000000000000000000000000a' by using Node.js?

You can use web3.toHex(number) to convert decimal number to hex then using web3.utils.padLeft("0x0abcdef", 64) to format the hex string to a 64 byte length hex

https://web3js.readthedocs.io/en/1.0/web3-utils.html#padleft

and reverse it from '0x000000000000000000000000000000000000000000000000000000000000000a' to uint 10 ?

just simply use web3.toDecimal() function to convert any hex string to decimal

0

Got it. My example is:

var a = 10
console.log(a); //output :10
var b = web3.utils.toHex(a);  
console.log(b); //output :0xa
var c = web3.utils.padLeft(b, 64);
console.log(c);  //output :0x000000000000000000000000000000000000000000000000000000000000000a
var d = web3.utils.toDecimal(c)
console.log(d); //output :10

Not the answer you're looking for? Browse other questions tagged or ask your own question.