ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 170929_TIL(php 비트 연산자)
    php 2017. 9. 29. 11:33

    개발하면서 << 나 >> 이런 연산이 어떻게 돌아가는 것인지 이해하기 어려웠다.


    http://php.net/manual/kr/language.operators.bitwise.php


    여기 매뉴얼을 보면서 알게 된것이 


    << 는 이후 숫자만큼 2씩 곱하기 한것

    >> 는 이후 숫자만큼 2씩 나누기 한것


    아래는 예제 및 설명이다.


    Just learning Bitwise Shift Operators. 

    The easiest way to resolve a bitwise  shift operators is my multiply or dividing each step by two for left shift or right shift respectively 

    Example: 

    LEFT SHIFT 
    <?php echo << 3//64 ?> 

    //same as 
    <?php echo 2?> 

    RIGHT SHIFT 
    <?php echo >> 3//1 ?> 

    //same as 
    <?php echo ((8/2)/2)/2//1 ?> 

    //Solving on a paper 8/2 = 4/2 = 2/2 = 1

    'php' 카테고리의 다른 글

    170918_TIL(slim framework 생성)  (0) 2017.09.18
Designed by Tistory.