Search code examples
c#convertersint32console.readline

Converting decimal to binary with user input


I wanna make a c# application that convert a decimal number into binary with the input from the user. I get a red squiggly line on bin, when declaring bin = Convert.ToString(decToBin,2);. I don't understand my problem, so any help would be appreciated.

int decToBin;
Console.WrinteLine("Enter a number that will be converted to binary")
decToBin = Int32.Parse(Console.Readline());

bin = Convert.ToString(decToBin,2);

Console.ReadKey();

Solution

  • i guess you haven't declared bin. it should be

    int decToBin;
    Console.WriteLine("Enter a number that will be converted to binary");
    decToBin = Int32.Parse(Console.ReadLine());
    string bin = Convert.ToString(decToBin, 2);
    Console.WriteLine(bin);