我有一個大的文本,其中包含一個數字作爲二進制值。例如'123'將是'001100010011001000110011'。編輯:應該是1111011C#將大的二進制字符串轉換爲十進制系統
現在我想將其轉換爲十進制系統,但數字太大,int64。
所以,我想要:將一個大的二進制字符串轉換爲十進制字符串。
我有一個大的文本,其中包含一個數字作爲二進制值。例如'123'將是'001100010011001000110011'。編輯:應該是1111011C#將大的二進制字符串轉換爲十進制系統
現在我想將其轉換爲十進制系統,但數字太大,int64。
所以,我想要:將一個大的二進制字符串轉換爲十進制字符串。
這將這樣的伎倆:
public string BinToDec(string value)
{
// BigInteger can be found in the System.Numerics dll
BigInteger res = 0;
// I'm totally skipping error handling here
foreach(char c in value)
{
res <<= 1;
res += c == '1' ? 1 : 0;
}
return res.ToString();
}
我的計算器說,1100010011001000110011₂等於3224115₁₀,不123₁₀。對於Int64,3224115√10不是太大。 – dtb 2012-01-07 23:50:42
你是用Google搜索嗎?我發現這個:http://cboard.cprogramming.com/csharp-programming/123317-convert-binary-decimal-string.html – fury 2012-01-07 23:52:25
你是如何得到從十進制到十進制001100010011001000110011二進制? – 2012-01-07 23:52:30