C#判断二进制是否是回文

using System;public class Demo {public static long funcReverse(long num) {long myRev = 0;while (num 0) {

编程学习网为您整理以下代码实例,主要实现:C#判断二进制是否是回文,希望可以帮到各位朋友。

using System;

public class Demo {
   public static long funcReverse(long num) {
      long myRev = 0;
      while (num > 0) {
         myRev <<= 1;
         if ((num & 1) == 1)
            myRev ^= 1;
      num >>= 1;
   }
   return myRev;
}

public static bool checkpalindrome(long num) {
   long myRev = funcReverse(num);
   return (num == myRev);
}

public static voID Main() {
   // Binary value of 5 us 101
   long num = 5;
   if (checkpalindrome(num))
      Console.Writeline("palindrome Number");
   else
      Console.Writeline("Not a palindrome Number");
   }
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐