[問題] 不知道哪邊寫得有問題
原po最近剛剛接觸C#
在練習寫10進位轉2進位時
不知道為什麼一直改都改不太對
想請版上的大家可以告訴我哪邊有問題
還是這樣寫根本不好之類的ˊˋ
謝謝大家
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace prog4
{
class Program
{
static void Main(string[] args)
{
string sa;
double n;
Console.Write("input number:");
sa = Console.ReadLine();
n = double.Parse(sa);
int x = (int)n;
double y = n - x;
string sum = "";
while (x != 0)
{
if (x % 2 == 0)
{
sum += 0;
}
else
{
sum += 1;
}
}
x = x / 2;
string a = Reverse() + ".";
while (y > 0)
{
if (y * 2 - 1 >= 0)
{
a += 1;
y = y * 2 - 1;
}
else
{
a += 0;
y = y * 2;
}
}
}
public static string Reverse(string strsource)
{
if (!string.IsNu110rEmpty(strsource))
{
try
{
char[] charArray = strSource.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
catch (Exception)
{
throw;
}
}
else
{
return "";
}
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.73.107
推
12/10 14:25, , 1F
12/10 14:25, 1F
→
12/10 14:25, , 2F
12/10 14:25, 2F
→
12/10 14:26, , 3F
12/10 14:26, 3F
→
12/10 14:26, , 4F
12/10 14:26, 4F
→
12/10 14:26, , 5F
12/10 14:26, 5F
推
12/10 21:55, , 6F
12/10 21:55, 6F
推
12/10 21:55, , 7F
12/10 21:55, 7F
→
12/12 01:18, , 8F
12/12 01:18, 8F