Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

คำนวณการหารโมดูลัสด้วยเลขยกกำลัง 2 ใน C #


เราได้นำตัวเลขดังต่อไปนี้ -

uint a = 9;
uint b = 8;

ด้านบน a เป็นตัวหาร และ b คือเงินปันผล

เพื่อคำนวณการหารโมดูลัส

ตัวอย่าง

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));
   }
}

ผลลัพธ์

9 modulus 6 = 1