In a smart contract I have stored a bytes4
value: 0xa22cb465
. I'd like to parse this value as a string:
string memory test = "0xa22cb465"
I've only stumbled upon explanations on how to convert bytes to string, not parse. Thanks in advance for the help!
Best Answer
If I understand correctly by "parsing" you mean going from an integer representation (i.e.,
bytes4 data = 0xa22cb465;
) to a string representation in hexadecimal (i.e.,string memory test = "0xa22cb465"
).In that case, you'd need to write a function to actually do that conversion. Here is an example working with bytes input and base 16 string output with "0x" prefix.
I hope that answers your question.