Help me please..
I can't make this code in window form application..

using System;

namespace _01.Decimal_to_Binary
{
    class DecimalToBinary
    {
        static void Main(string[] args)
        {
            Console.Write("Decimal: ");
            int decimalNumber = int.Parse(Console.ReadLine());

            int remainder;
            string result = string.Empty;
            while (decimalNumber > 0)
            {
                remainder = decimalNumber % 2;
                decimalNumber /= 2;
                result = remainder.ToString() + result;
            }
            Console.WriteLine("Binary:  {0}",result);
        }
    }
}

please help me..
thanks

Recommended Answers

All 4 Replies

You need to supply a bit more detail about what you are trying to do

Aren't you supposed to be adding '0' or '1' to result instead of remainder.ToString()?

Create your form, put a textbox, a label and a button on it. Put the conversion code inside the 'click' event of the button. Use the value from the textbox rather than from ReadLine(). Put the result in the label.

As momerath stated, you need differenrt approach then in Console. You need some controls, where you will insert your data (exchange Textbox control for Console.ReadLine() method).
Then insert a Label, where yo will show results (exchnage for Console.WriteLine() method).
And use same method as you are using now for do the calculation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.