From solidity docs, in section Layout of State Variables in Storage > bytes and strings
There is this explanation (v: v0.8.21):
In particular: if the data is at most 31 bytes long, the elements are stored in the higher-order bytes (left aligned) and the lowest-order byte stores the value length * 2. For byte arrays that store data which is 32 or more bytes long, the main slot p stores length * 2 + 1 and the data is stored as usual in keccak256(p). This means that you can distinguish a short array from a long array by checking if the lowest bit is set: short (not set) and long (set).
The way I understand it, in both cases, short or long there would be something at the lowest order bit location.
In short string case, last bytes would have
length * 2.
For example, string
hello would look like
hello there would look like
0x68656c6c6f207468657265000000000000000000000000000000000000000016. These are both under 32 characters and have their length times 2 in lowest significant bits as expected.
In long string case, least order bits (and the only item in that storage location) would have
length * 2 + 1.
hello therehello therehello therehello therehello therehello therehello there would look like
Again, the lowest order bits would contain the length information, this time
length * 2 + 1.
My confusion is with the last sentence from above docs:
This means that you can distinguish a short array from a long array by checking if the lowest bit is set: short (not set) and long (set).
Is this a remnant from an older version of solidity where short strings did not have their length information as part of the storage slot? By just looking at the least significant bits (as that sentence implies), how can we tell if something is a short version string or a long version string? Am I missing something here or do docs just need to be updated here?