0

I'm using a fixed-point math library that works with binary numbers, so values like 0x10000000000000000 are assumed to be 1.

I implemented a function that raises a given number to a given power. Raising 0x10000000000000000 to the power of 2 yields the same number:

Remix Caption

I would prefer the result to show up as 0x10000000000000000 rather than 18446744073709551616, the latter being of course the former converted to decimal. Can I make Remix display numbers as hex?

My function:

function doPow(int128 x, uint256 y) external pure returns (int128) {
    return ABDKMath64x64.pow(x, y);
}
3
  • Have you tried returning a bytes memory instead of an integer? I've tested a simple function that returns bytes and it seems to work as you want, but I'm not sure since you're working with binary numbers. To clarify, I'm using abi.encodePacked.
    – alberto
    Commented Mar 17, 2021 at 12:08
  • 1
    Thanks, Alberto! I added an answer based on your suggestion. Commented Mar 17, 2021 at 12:19
  • I just discovered this number converter tool developed ABDK, the same guys who developed the ABDKMath64x64 library. Commented Mar 22, 2021 at 13:20

1 Answer 1

1

Based on @alberto's suggestion in the comment, I changed the return type from int128 to bytes memory and re-wrote my function like this:

function doPow(int128 x, uint256 y) external pure returns (bytes memory) {
    int128 result = ABDKMath64x64.pow(x, y);
    bytes memory encodedResult = abi.encodePacked(result);
    return encodedResult;
}

Now the result shows up like this:

Remix Caption

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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