Description
Is there any reason bitwise shifting was omitted from the EVM? Other bitwise operators are present.
In the past few months in Solidity it was a challenge to deal with arbitrary data and even efficiently implement something like hex to string or string to hex conversion.
Rudimentary shift alternatives are: a * (2 ** b)
for shl and a / (2 ** b)
for shr. One can use SIGNEXTEND
to implement arithmetic right shift. (Using this to implement shift in Solidity: ethereum/solidity#527. Having a progression path to native shifting would make sense.)
While there are some alternative opcodes in certain cases (such as the BYTE
and MSTORE8
) I still think it would be a very useful addition to have native logical shifts (SHL and SHR). I am not fully convinced about the necessity of arithmetic right shift (SAR). Additionally bit rotation (ROR/ROL) might make sense.
@chfast @gcolvin I know you were discussing the option to have 64 bit arithmetic. Did you think about including bit shifting?