-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Amit Kumar
authored
Jun 22, 2017
1 parent
9b3ee26
commit d0703ad
Showing
1 changed file
with
18 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
# bitwise-operator | ||
Bitwise Operator | ||
# Bitwise Operator | ||
|
||
> The operands of all bitwise operators are converted to signed 32-bit integers in two's complement format.Every number has it's own binary representation, used by those operators. To check dec number's binary value, we use `.toString()` method with base argument - '2' for binary. | ||
**Sometime we even use Bitwise OR as equivalent of Math.floor()** | ||
``` | ||
Example - | ||
var temp = 2.987293874; | ||
var result = temp | 0; | ||
``` | ||
|
||
**Few Uses of bitwise operator** | ||
|
||
- We can convert colors from RGA to Hex format. | ||
- Variables swap without using third variable (hint - using xor)(redundant with ES6 swap [a, b] = [b, a]). | ||
- Example section of [https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators]. | ||
- Check if number is even or odd `Even Number => [(n & 1) === 0]` | ||
- https://miguelmota.com/blog/bitwise-operators-in-javascript/ |