pragma solidity ^0.4.20;

contract TestBytes32ToString{
    function bytes32ToString(bytes32 x) public pure returns(uint,uint,uint,string memory){
        bytes memory bytesString = new bytes(32);
        uint charCount = 0;
        for(uint i = 0; i < 32; i++){
            byte char = byte(bytes32(uint(x)*2**(8*i)));
            if(char != 0){
                  bytesString[charCount] = char;

        bytes memory bytesStringTrimmed = new bytes(charCount);
        for(i = 0; i < charCount; i++){
            bytesStringTrimmed[i] = bytesString[i];
        return (uint(x),uint(x)*2**(8*0),uint(x)*2**(8*1),string(bytesStringTrimmed));

When I execute the above code in the new layout of remix,I input "0x6c",then an error had occurred as follws:

Error encoding arguments: Error: invalid bytes32 value (arg="", coderType="bytes32", value="0x6c", version=4.0.37) 

enter image description here

But I did the same operation in the previous version of remix, it works.

enter image description here

2 Answers 2


That's because the value has to be 32 bytes long in the new layout, like:


From remix-ide github:

if you specify bytes32, then the value has to be 32 bytes long. If you don't mean that, you could use a shorter length, the types string or bytes.

Duplicated issue with the same question here.


Most of the time we try to provide string but it will be byte32 in following format. // 'ETH' as a bytes32 string '0x4554480000000000000000000000000000000000000000000000000000000000'

Do not forget to remove single cote at the time of input.

Your Answer

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

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