Using Binary Flags : Integer « Number Data Type « JavaScript Tutorial






<html>
<head>
<title>Using Binary Flags</title>
<script type="text/javascript">
var FIELD_A = 0x1;  // 00001
var FIELD_B = 0x2;  // 00010
var FIELD_C = 0x4;  // 00100
var FIELD_D = 0x8;  // 01000
var FIELD_E = 0x10; // 10000

var fieldsSet = FIELD_A | FIELD_C | FIELD_E;

if ((fieldsSet & FIELD_A) && (fieldsSet & FIELD_C)) {
   document.write("Fields A and C are set");
}

</script>
</head>
</body>
</html>








5.3.Integer
5.3.1.Integers
5.3.2.Integers can also be represented as either octal (base 8) or hexadecimal (base 16) literals.
5.3.3.To create a hexadecimal literal, the first digit must be a zero (0) followed by the letter x, followed by any number of hexadecimal digits (0-9 and A-F).
5.3.4.Define and use integers
5.3.5.Calculation on integers
5.3.6.Compare two numbers
5.3.7.Generate random number
5.3.8.Using Binary Flags