BitMath: Addition
Description:
Create a utility function called add
for your BitMath
class, which will use bitwise operators (&, |, ^, ~, <<**, **>>, and >>>) to add 2 integers a
and b
without the use of the basic arithmetic operators (+, -, *****, /, and %).
As bitwise operation converts its operands to 32-bit signed integers, parameters in the test cases will be constrained such that:
-230 ≤ a
≤ 230 - 1,
-230 ≤ b
≤ 230 - 1
Examples:BitMath.add(1, 1)
--> 2
BitMath.add(2, 2)
--> 4
BitMath.add(27, 15)
--> 42
Read up on bitwise operators here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
Note:
Don't comment your code, as //
will detected as a false positive instance of the division operator.
The increment, decrement, unary negation, and unary plus operators are also disallowed.
If you've enjoyed this kata, also check out:
BitMath: Multiplication
Similar Kata:
Stats:
Created | Aug 7, 2016 |
Published | Aug 19, 2016 |
Warriors Trained | 254 |
Total Skips | 3 |
Total Code Submissions | 583 |
Total Times Completed | 124 |
JavaScript Completions | 124 |
Total Stars | 6 |
% of votes with a positive feedback rating | 87% of 55 |
Total "Very Satisfied" Votes | 43 |
Total "Somewhat Satisfied" Votes | 10 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 13 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |