Using Binary Flags : Number « Data Type « JavaScript DHTML






Using Binary Flags

   

<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>

   
    
    
  








Related examples in the same category

1.Convert a number to a precision
2.Fix a number
3.Convert a Number to a Exponential format
4.Convert a number to string by append empty string to it
5.Compare the value for integer numbers
6.Integer math calculation
7.Calculate the average for integers
8.Convert from Celsius to Fahrenheit
9.Convert Fahrenheit to Celsius
10.Calculate circle area/Peri/Calculate sphere volume
11.Declare float point number, boolean value and null value
12.Hexadecimal Numbers
13.Check if it is a number and calculate the cubic power
14.Read a number and compare its value
15.Add different type variables together