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?

1
  • Here's a similar question. Commented Sep 18, 2014 at 17:47

1 Answer 1

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"))
             );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.