PHP Bitwise

  1. What are the php bitwise operators?
    • ~ (NOT)
    • & (AND)
    • | (OR)
    • ^ (XOR) exclusive or
    • << SHIFT BITS LEFT
    • >> SHIFT BITS RIGHT
  2. Shifting a number 1 bit to the left is the same of ________ by 2
    Multiplying
  3. Shifting a number 1 bit to the right is the same of ________ by 2
    Dividing
  4. var_dump(6&3);
    2

    • 00000110 6
    • 00000011 &3
    • 00000010 2
  5. To find out the max value of an integer we use the constant
    • 'PHP_INT_MAX'To find out the size of an integer we use the constant
    • 'PHP_INT_SIZE'
  6. What is the sun of the binary bits,
    1 + 1 ?
    10
  7. Image Upload 2
  8. What is the output of the following:
    <?php
    $a = 2;
    print ~$a++;
    ?>
    • output is -3
    • //++ has higher precendent than ~ so $a++ is executed first.
    • But since $a++ is post-increment the value remains 2;
    • then the binary bits of 2 is negated which results in the value
    • being negative -3.
  9. What is the output of the following:
    <?php
    $a = 4;
    print ~++$a;
    ?>
    • output is -6
    • // $a++ is pre-increment the value becomes 5;
    • then the binary bits of 5 is negated which results in the value being negative -6.
  10. What is the out of :

    print 20 % 3
    2
  11. what is output of :

    print 0 % 8;
    8
  12. what is output of :

    print 7 % 11;
    7
  13. put the following in order based on their precedent
    1) left << >>
    2)right = += -= *= /= .= %= &= |= ^= <<= >>=
    3) non [] ()
    4)left &&
    6) right new
    7)left XOR
    8) left + - .
    9)left ^
    14)left OR
    15) left * / %
    16) non == != === !==
    17)left |
    18) right !~ ++ -- (int)(float)...@
    19)left ||
    20)left AND
    10)left ? :
    11) non < <= > > = <>
    12)left ,
    13)left &
    • 6
    • 3
    • 18
    • 15
    • 8
    • 1
    • 11
    • 16
    • 13
    • 9
    • 17
    • 4
    • 19
    • 10
    • 2
    • 20
    • 7
    • 14
    • 12
  14. what is the output of the following
    $b = 2;
    $z = 7 + (2 * 3) + $b *= 6 - 4 << 2;
    print $z;
    • output is : 29
    • $z = (7 + (2 * 3)) + $b *= ((6 -4) << 2);
    • $z = 13 + $b *= 8;
    • $z = 13 + 16;
    • $z = 29;
  15. $b = 3;
    $z = 4 << 2 + 5 + $b *= 2 * 3;
    • output is 530:
    • $z = (4 << (2 + 5)) + $b *= (2 *3);
    • $z = 4 << 7 + $b *= 6;
    • $z = 4 * 128 + $b *= 6;$
    • z = 512 + ($b *= 6);
    • $z = 512 + 18;
    • $z = 530;
  16. What is the output of the following:
    $b = 2;
    $c = 1;
    $z = 3 + 2 << 2 + $b += 3 * $c * = 1;
    print $z;
    • //output is 128
    • //($c *= 1) needs to be evaluated so that we
    • //can multiply
    • $z = 3 + 2 << 2 + $b += (3 * ($c *= 1));
    • $z = (3 + 2) << (2 + ($b += 3));
    • $z = 5 << 7;
    • $z = 5 * 128;
    • $z = 128
    • $z = 640;
    • $z = 128;
  17. in which direction is
    ~ - (int) (float) (string) (array) (object) (bool) @
    evaluated?
    RIGHT to LEFT
  18. in which direction is
    * / % + - .
    evaluated?
    LEFT to RIGHT
  19. in which direction is
    << >>
    evaluated?
    LEFT to RIGHT
  20. in which direction is
    & ^ |
    evaluated?
    LEFT to RIGHT
  21. in which direction is
    && || ? :
    evaluated?
    LEFT to RIGHT
  22. in which direction is
    = += -= *= /= .= %= &= |= ^= <<= >>=
    evaluated?
    RIGHT to LEFT
  23. in which direction is
    and xor or ,
    evaluated?
    LEFT to RIGHT
  24. in which direction is
    < <= > >= <> == != === !==
    evaluated?
    They are NON Associative
Author
starkisspk
ID
9582
Card Set
PHP Bitwise
Description
Everything Bitwise and Operators
Updated