Compute modulus division by a power-of-2-number in C#

CsharpProgrammingServer Side Programming

We have taken the number as the following −

uint a = 9;
uint b = 8;

Above, a is a divisor and b is dividend.

To compute modulus division.

Example

 Live Demo

using System;
class Demo {
   static uint display( uint a, uint b) {
      return ( a & (b-1) );
   }
   static public void Main () {
      uint a = 9;
      uint b = 6;
      Console.WriteLine( a + " modulus " + b + " = " + display(a, b));
   }
}

Output

9 modulus 6 = 1
raja
Published on 17-Sep-2018 16:41:12
Advertisements