How to use Bitwise Operator In Javascript
In this approach, we will be using the Bitwise Operators. The bitwise operators in JavaScript allow us to get the quotient and remainder of a division. For instance, using the bitwise NOT or bitwise OR |0, which transforms the floating-point value to an integer, we may get the quotient of a division. We may also use the% character to retrieve the remaining value. Find the remainder and quotient of 14 divided by 5, for instance. Check out the code below.
Example: This example shows the implemetation of the above-explained approach.
Javascript
let a = 14; let b = 5; let q = ~~(a / b); let r = a % b; console.log( 'Quotient = ' , q, 'Remainder = ' , r); |
Quotient = 2 Remainder = 4
Division in JavaScript
In every programming language, the operation of division is used often. The division operator (/) is used in JavaScript to divide integers. You may use the division operator or a predefined JavaScript technique that treats every number as an integer to divide two values.
Use the techniques listed below to divide two numbers:
Table of Content
- Division (/) Operator
- JavaScript parseInt() Method
- Using math library in JavaScript
- Using Bitwise Operator