Solidity Shifting

Solidity Programming Language
3 min readMar 3, 2023

--

Today we talk about shifting concept in solidity language. You need to know how shift’s operators use and when shift’s operators use in the solidity world.

Keep on jumping.

Once you use these operators in the function, you can see that these operators either divide or multiply your input values.

Left operator <<

You can use this operator for multiplying the your input value. A left shift by 1 position is analogous to multiplying by 2

Right operator >>

You can use this operator for multiplying the your input value.A right shift by 1 position is analogous to dividing by 2

When you increase the “1" on the function, you will see that the results change.

You can see the results in the remix.

We can use thse operators for multiplying and dividing the input value also we shift the bits of input value to the left/right by one position.

You need to change value type as a bytes for understanding the bit’s shifting.

I can explain. Calm down !

What is 0x14 ?

0X14 << 1 = 0x28

We shift the bits of X to the left by one position, resulting in the binary number 101000, which is equivalent to the decimal number 40.

0X14 >> 1 = 0x0a

We shift the bits of X to the right by one position, resulting in the binary number 1010, which is equivalent to the decimal number 10.

We also use these operator in masking operations.

Doç.Dr.Engin YILMAZ

--

--

Solidity Programming Language

Solidity basics for beginners: Learn the fundamentals of smart contract development and build your first DApp! #Solidity #Foundry #Ethereum #Opcodes #DApps