I am using this code in converting address to string in solidity
function toAsciiString(address x) public returns (string memory) {
bytes memory s = new bytes(40);
for (uint i = 0; i < 20; i++) {
bytes1 b = bytes1(uint8(uint(uint160(x)) / (2**(8*(19 - i)))));
bytes1 hi = bytes1(uint8(b) / 16);
bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi));
s[2*i] = char(hi);
s[2*i+1] = char(lo);
}
return string(abi.encodePacked("0x",s));
}
function char(bytes1 b) public returns (bytes1 c) {
if (uint8(b) < 10) return bytes1(uint8(b) + 0x30);
else return bytes1(uint8(b) + 0x57);
}
Input : 0x4a9C121080f6D9250Fc0143f41B595fD172E31bf
Output: 0x4a9c121080f6d9250fc0143f41b595fd172e31bf
As you can see, there is a capitalization issue. The output should be same as input but capital letters in input are coming out as small letters. I am running this code in remix. Please let me know if there is any fix.