Page 75 - JavaScript
P. 75

// truth table
         // 1010 | (or)
         // 0011
         // 1011  (result)


        Bitwise and



         a = 0b0011 & 0b1010; // a === 0b0010
         // truth table
         // 1010 & (and)
         // 0011
         // 0010  (result)


        Bitwise not



         a = ~0b0011; // a === 0b1100
         // truth table
         // 10 ~(not)
         // 01  (result)



        Bitwise xor (exclusive or)


         a = 0b1010 ^ 0b0011; // a === 0b1001
         // truth table
         // 1010 ^ (xor)
         // 0011
         // 1001  (result)


        Bitwise left shift



         a = 0b0001 << 1; // a === 0b0010
         a = 0b0001 << 2; // a === 0b0100
         a = 0b0001 << 3; // a === 0b1000


        Shift left is equivalent to integer multiply by Math.pow(2, n). When doing integer math, shift can
        significantly improve the speed of some math operations.


         var n = 2;
         var a = 5.4;
         var result = (a << n) === Math.floor(a) * Math.pow(2,n);
         // result is true
         a = 5.4 << n; // 20


        Bitwise right shift >> (Sign-propagating shift) >>> (Zero-fill right shift)



         a = 0b1001 >> 1; // a === 0b0100
         a = 0b1001 >> 2; // a === 0b0010
         a = 0b1001 >> 3; // a === 0b0001

         a = 0b1001 >>> 1; // a === 0b0100



        https://riptutorial.com/                                                                               32
   70   71   72   73   74   75   76   77   78   79   80