Skip to content

Commit 7d41054

Browse files
raphaelmdcoelhoaalhour
authored andcommitted
Bitwise operator (#59)
* Bitwise operator Using Bitwise operator (&) "r" will recives the modulus result like modulus operator "%" is doing, but is more efficient and fast. * Comment Bitwise operator Added a comment to explaing why use bitwise operator.
1 parent c04aa06 commit 7d41054

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Algorithms/Numeric/GreatestCommonDivisor.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ public static uint FindGCD(uint a, uint b)
1919
return a;
2020

2121
uint _a = a, _b = b;
22-
uint r = _a % _b;
22+
23+
//Bitwise operator '&' works on individual bits of each value
24+
//result is 0 or 1
25+
//it works like a modulus operator '%' but is more efficient
26+
uint r = _a & _b;
2327

2428
while(r != 0)
2529
{
2630
_a = _b;
2731
_b = r;
28-
r = _a % _b;
32+
r = _a & _b;
2933
}
3034

3135
return _b;

0 commit comments

Comments
 (0)