Q6/ Write a C# Program to Convert the Decimal Number to Binary Number.

Solution: int d,a; d = int.Parse(Console.ReadLine()); string dec = ""; while (d >= 1) { a = d / 2; dec += (d % 2); d = a; } string bin = ""; for (int i = dec.Length - 1; i >= 0; i--) { bin = bin + dec[i]; } Console.Write("The Binary number Console.Read(); is {0}",bin);

Q7/ Write a C# Program to Convert the Binary Number to Decimal Number.
Solution: int DecimalNumber = 0, BinaryNumber, power = 1; BinaryNumber = Convert.ToInt32(Console.ReadLine()); while (BinaryNumber > 0) { DecimalNumber += BinaryNumber % 10 * power; BinaryNumber = BinaryNumber / 10; power = power * 2; } Console.WriteLine("The decimal Number is {0}",DecimalNumber); Console.ReadLine();