If I do the following in golang:
data := []byte{}
data = append(data, '1')
data = append(data, '2')
fmt.Printf("%d
", len(data))
fmt.Printf("%x
", fmt.Sprintf("%d", len(data)))
I get 2 and 32, respectively, instead of just 2 on both lines (obviously the array has only two elements).
If I do something similar-ish in solidity:
bytes memory encodedPack = abi.encodePacked(prefix, length, signedMessage)
The encodePacked
function also prepends the length with 3 in the final byte array.
According to the ASCII table, 3 represents "end of text". Is this what this 3 is for?
Sprintf()
returns a string. You are printing the string "2" which in ASCII is 0x32
.
The 3 here is not end-of-text. If you look at the ASCII table, you will notice that the characters "0" to "9" are encoded as 0x30
until 0x39
.