Decimal

suggest change

The 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Tilde:
* Tilde
* Decimal

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde