Utilizing JavaScript Operators . 101 Although you will
Tuesday, May 8th, 2007Utilizing JavaScript Operators . 101 Although you will probably never use bitwise operators, let s learn how the results are calculated. All calculations will be performed in hexadecimal and binary bases, because 7 they are most convenient for the task. Remember that hexadecimal numbers have a 0x prefix. Let s take a look at the following numbers, and how the bitwise AND operates on them: 0×23 001000112 & 0×72 011100102 = 0×22 001000102 Chapter 0×23&0×72//evaluatesto34(=0×22=2216) The bitwise AND operator is similar to the logical AND operator, which is discussed later in this chapter. You can use the bitwise AND operator to test whether a number is even or odd. In binary (base 2), the last digit of an odd number is 1, and the last digit of an even number is 0. The following function uses the bitwise AND operator to determine whether the number is odd or even. It returns true if decimalNumber is even, and false if it is odd. functioncheckEven(decimalNumber) { return(decimalNumber&1==0) } Don t worry if you are not familiar with the == equality operator. It is introduced later in this chapter. Come back to this script after we discuss the equality operator. Bitwise OR operand1|operand2 The OR operator, also known as the inclusive OR operator, compares its operands. It returns 1 if at least one of the compared bits is 1. Table 7-5 shows the operator s truth table. Table 7-5. Bitwise ORtruth table. Bit1Bit2Bit1|Bit2 0 0 0 0 1 1 1 0 1 1 1 1
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services