Reputation: 2060
I'm trying to convert binary data (string) to hexa decimal data (string)
string BinaryData = 1011000000001001001000110100010101100111100000000001000001111011100010101011";
string HexaDecimalData = Convert.ToInt64 ( BinaryData, 2 ).ToString ( "X" );
I get a OverflowException : Value was either too large or too small for a UInt64
. I can understand that the binary string is big, but at the same I cant think of any bigger data type than Int64.
any suggestions?
Upvotes: 2
Views: 366
Reputation: 15354
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"))
);
Upvotes: 5