The bitwise NOT is represented by a tilde (~).
The bitwise NOT is a three-step process:
- The operand is converted to a 32-bit number.
- The binary form is converted into its one's complement.
- The one's complement is converted back to a floating-point number.
var iNum1 = 25; //25 is equal to 00000000000000000000000000011001
var iNum2 = ~iNum1; //convert to 111111111111111111111111111100110
alert(iNum2); //outputs "-26"
<html>
<script language="JavaScript">
<!--
// integer = 32-bit binary representation
// 2 = 00000000000000000000000000000010
// -3 = 11111111111111111111111111111101
// -2 = 11111111111111111111111111111110
// -1 = 11111111111111111111111111111111
document.write("~2 = ",(~2)); //Displays -3
-->
</script>
</html>