0
Write a program to enter any number from user and convert into Binary number e.g we enter 10 and his answer display 1010
can you help me please??? I'm very troubling in coding to write a program in C#
2 Answers
+ 11
using System;
namespace ToBin
{
class Program
{
static public string ToBinary(int num)
{
string result = "";
if (num == 0)
return "0";
while ( num != 0 )
{
result = num % 2 + result;
num = num / 2;
}
return result;
}
static void Main(string[] args)
{
int number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(ToBinary(number));
}
}
}
---------------------------------
or just use the built in Convert.ToString( your_number, base=2 ). Check here for full details:
https://msdn.microsoft.com/en-us/library/8s62fh68(v=vs.110).aspx
0
thank you very much Sir Nikolay Nachecđđđđ