Skip to content

Instantly share code, notes, and snippets.

@alexisljn
Created June 22, 2022 08:54
Show Gist options
  • Save alexisljn/f6b18f6f644fc44e46bb1b34a7204797 to your computer and use it in GitHub Desktop.
Save alexisljn/f6b18f6f644fc44e46bb1b34a7204797 to your computer and use it in GitHub Desktop.
This gist shows how to convert bytes input into an uint output. Then we can retrieve the bytes input by converting the uint value into an hexadecimal string
//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
import "@openzeppelin/contracts/utils/Strings.sol";
contract Test {
uint256 public value;
using Strings for uint256;
function hexToUint(bytes32 _value) public {
value = uint256(_value);
}
function uintToHexString() public view returns(string memory) {
return value.toHexString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment