2

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?

SanVEE
  • 2,009
  • 5
  • 34
  • 55
  • Here's a [similar question](http://stackoverflow.com/questions/5612306/converting-long-string-of-binary-to-hex-c-sharp). – sgbj Sep 18 '14 at 17:47

1 Answers1

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"))
             );
EZI
  • 15,209
  • 2
  • 27
  • 33