[Ethereum] Integer to hexadecimal number

contract-developmentsolidity

I am working on a contract in which I have a requirement to convert an integer to hexadecimal number. Suppose I have a number 234 its hexadecimal format is EA so how would I perform this in solidity. Please, someone help me with this.

Best Answer

In my opinion that sort of operation is almost always avoidable and it should be avoided even at the price of great inconvenience to client software.

There are plenty of reasons. Two that stand out:

  1. Inside the contract, compute resources are scarce and expensive and errors may be catastrophic and irreversible. Maximize simplicity.
  2. Client-side, compute resources are plentiful and cheap and any errors or oversights can be resolved with ease. There is nothing unreasonable about pushing responsibilities to software clients.

Carry on as though client convenience is of no concern at all. Some elaboration on the idea: https://medium.com/solidified/the-joy-of-minimalism-in-smart-contract-design-b67fb4073422

Hope it helps.