Table of contents Home page
Execute this code
// Operator precedence: 11 // Operator associativity: left-to-right // With a positive number alert("8 >> 1 = " + (8 >> 1)) // 8 is 00000000 00000000 00000000 00001000 in binary notation // All the bits are shifted 1 position to the left, the right-most bit is discarded // and the vacant left-most position is filled with 0, so we get: // 00000000 00000000 00000000 00000100 // And this is 4 in decimal notation // With a negative number // 00000000 00000000 00000000 00001000 (decimal 8) // 11111111 11111111 11111111 11110111 (reversed all bits) // 11111111 11111111 11111111 11111000 (added 1, the result is the binary two's complement notation of -8) alert("-8 >> 1 = " + (-8 >> 1)) // All the bits are shifted 1 position to the left, the right-most bit is discarded // and the vacant left-most position is filled with 1, so we get: // 11111111 11111111 11111111 11111100. // And this is -4 in decimal notation