HTML and CSS Reference
EXPLANATION ( CONTINUED )
When the bitwise | (OR) operator is applied to 1111 | 1001 , the result is binary
1111 or decimal 15.
When the bitwise ^ (Exclusive OR) is applied to 1111 ^ 1001 , the result is binary
0110 or decimal 6.
9<<2 yields 36, because 1001 shifted two bits to the left becomes 100100, which
is decimal 36.
9>>2 yields 2, because 1001 shifted two bits to the right becomes 10, which is dec-
-9 >> 2 yields -3 , because the sign is preserved.
15 >>> 2 yields 3, because 1111 shifted two bits to the right becomes 0011, which
is decimal 3. For nonnegative numbers, zero-fill right shift and sign-propagating
right shift yield the same result. (See Figure 5.19.)
Figure 5.19 Output from Example 5.13.
Data Type Conversion
have to be concerned about what kind of data is stored in a variable. You can assign a num-
ber to x on one line and on the next line assign a string to x , you can compare numbers
when it assigns values to a variable or evaluates an expression. If data types are mixed (i.e.,
a number is compared with a string, a Boolean is compared with a number, a string is com-
force a conversion of one type to another. For example, if you prompt a user for input, the
input is set as a string. But, suppose you want to perform calculations on the incoming
data, making it necessary to convert the strings to numbers. When using the + operator
you want to add two numbers that have been entered as strings, not concatenate them, so
you will then need to convert the data from string to number.