我正在尝试将二进制数据(字符串)转换为十六进制数据(字符串)
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 :(得分: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"))
);