var iResult = 25 & 3; alert(iResult); //outputs "1" 25 = 0000 0000 0000 0000 0000 0000 0001 1001 3 = 0000 0000 0000 0000 0000 0000 0000 0011 --------------------------------------------- AND = 0000 0000 0000 0000 0000 0000 0000 0001
<html> <script language="JavaScript"> <!-- // integer = 32-bit binary representation // 12 = 00000000000000000000000000001100 // 6 = 00000000000000000000000000000110 // 4 = 00000000000000000000000000000100 x = 6; x &= 12; document.write("x = ",x); --> </script> </html>