Write a C# Sharp program to reverse the binary representation of an given integer and convert the reversed binary number into an integer
- برمجة سي شارب
- برمجة
- 2021-05-31
- ahmadghneem
الأجوبة
using System;
using System.Linq;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
int n = 120;
Console.WriteLine("Original number: " + n);
Console.WriteLine("Reverse the binary representation of the said integer and convert it into an integer: " + test(n));
n = 321;
Console.WriteLine("\nOriginal number: " + n);
Console.WriteLine("Reverse the binary representation of the said integer and convert it into an integer: " + test(n));
n = 43;
Console.WriteLine("\nOriginal number: " + n);
Console.WriteLine("Reverse the binary representation of the said integer and convert it into an integer: " + test(n));
n = 4433;
Console.WriteLine("\nOriginal number: " + n);
Console.WriteLine("Reverse the binary representation of the said integer and convert it into an integer: " + test(n));
}
public static int test(int n)
{
return (Convert.ToInt32(new string(Convert.ToString(n, 2).Reverse().ToArray()), 2));
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال