Why "<<" and ">>" are not considered as multiplication and division?


  • 2
    S

    They actually works as * 2 and / 2.


  • 0

    What language are you using? << and >> means left and right bitshift in C++. But it does have a different operator precedence, so you might need to wrap it around with parentheses or it will not work.


  • 0
    S

    In most of languages, << and >> mean shifting. bitwise shift acually mean *2 and /2. You r still multiplying, in a different way.


  • 0
    L

    Shifting is totally different from multiplication, they are different instructions. In most processors a shifting instruction takes just one cycle while a multiplication instruction takes tens of cycles


  • 0
    F

    multiplication means *n, << only means *2. for example, you can't use << to *3.


  • 0
    J

    actually you could , a << 1 + a == a * 3

    any number n has its binary representation...


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.