我試圖通過8位(每個8位= 1個ASCII字符)將位串轉換爲ASCII字符。將位串轉換爲字符
public string BitsToChar(string InpS)
{
string RetS = "";
for (int iCounter = 0; iCounter < InpS.Length/8; iCounter++)
RetS = System.String.Concat(RetS, (char)Convert.ToByte(InpS.Substring(iCounter * 8, 8)), 2);
return RetS;
}
它引發System.OverflowException:值對於無符號字節來說太大或太小。
對於我來說不清楚8位二進制字符串的8位部分對於8位字節類型來說可能太小或太大。
任何想法?謝謝。
Convert.ToByte()使用'decimal'表示,而不是'binary';所以例如「01000000」被視爲「一百萬」,並導致整數溢出 –
我認爲Convert.ToByte(str,2),我使用,與二進制。 – user3462831
這最初是一個字節數組?這很容易理解爲ASCII並從中得到一個字符串。 – BradleyDotNET