2014-09-18 66 views
2

我想二進制數據(串)轉換爲十進制六數據(串)如何將C#中的大二進制字符串轉換爲十六進制字符串格式?

string BinaryData = 1011000000001001001000110100010101100111100000000001000001111011100010101011"; 

string HexaDecimalData = Convert.ToInt64 (BinaryData, 2).ToString ("X"); 

我得到一個OverflowException異常:Value was either too large or too small for a UInt64。我可以理解,二進制字符串很大,但同樣我不能想到比Int64更大的數據類型。

有什麼建議嗎?

+0

這是[類似問題](http://stackoverflow.com/questions/5612306/converting-long-string-of-binary-to-hex-c-sharp)。 – sgbj 2014-09-18 17:47:22

回答

5
string BinaryData = "1011000000001001001000110100010101100111100000000001000001111011100010101011"; 

int count = 0; 
var hexstr = String.Concat(
       BinaryData.GroupBy(_ => count++/4) 
          .Select(x => string.Concat(x)) 
          .Select(x => Convert.ToByte(x, 2).ToString("X")) 
      ); 
相關問題