Smart    Lucky

Smart Lucky

  • NA
  • 555
  • 638.6k

Problem in Converting Decimal to Binaray

Jun 15 2011 2:53 AM
Hi 

i am trying to convert decimal to binary but problem is that it is not giving me proper result can any one help me.....? program is below..



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BinarayNumber
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Please Enter any number......");
            int number = int.Parse(Console.ReadLine());
            int reminder, value = 0;
            string binaray = null;
            for (int i = 0; i <= number; i++)
            {
                reminder = number % 2;
                value = number / 2;
                number = value;
                Console.WriteLine("Reminder is {0} , Value is {1} , Number is now {2}", reminder, value, number);
                reminder += value;
                binaray += reminder;
            }

            Console.WriteLine("Binray value is is" + binaray);
            Console.ReadKey();
        }
    }
}


Answers (3)