This is a question specific to the go-ethereum implementation. It may be present in other implementations, but I haven't looked yet.

In go-ethereum/common/bytes.go, the function isHex returns false if an input has an odd number of digits, and I was wondering why:

func isHex(str string) bool {
    if len(str)%2 != 0 {
        return false
    for _, c := range []byte(str) {
        if !isHexCharacter(c) {
            return false
    return true

1 Answer 1


In the context of Ethereum, hex is a set of bytes encoded in base 16. Since a byte is actually 256 values, it takes 2 hex characters to make up a byte. So if there are only 3 hex characters, you wouldn't know which pairs of characters made up the individual bytes.

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.