Decimal
suggest changeThe following example illustrates use of the bitwise NOT (~) operator on decimal numbers.
To keep the example simple, decimal number 3.5
will be used, cause of it’s simple representation in binary format.
let number = 3.5;
let complement = ~number;
Result of the complement
number equals to -4;
Expression | Binary value | Decimal value |
—— | —— | —— |
3.5 | 00000000 00000010.1
| 3.5 |
~3.5 | 11111111 11111100
| -4 |
To simplify this, we can think of it as function f(n) = -(integer(n)+1)
.
let a = ~-2.5; // a is now 1
let b = ~-1.5; // b is now 0
let c = ~0.5; // c is now -1
let d = ~1.5; // c is now -2
let e = ~2.5; // c is now -3
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents