1

i have string like

string test = "0x527AE53437CAED39D3E2A8B3E90FFC3BA9073B6D933BC05FF6677B5521DC34"

How can i convert the string to byte[]?

user2181707
  • 161
  • 3
  • 13
  • 1
    What do you mean "to hexadecimal"? It already looks like it is. Do you mean you want to convert it to a `byte[]` array? Or to a single huuuuuuuuge integer number? – Chris Sinclair Sep 13 '13 at 16:12
  • the hexadecimal number you posted is too **large**, I'm afraid that the largest integral number (`long`) can't hold it. – King King Sep 13 '13 at 16:13
  • Note that your title says "issue" but there is no problem show in your post. You are probably missed sample code that does not behave the way you want. – Alexei Levenkov Sep 13 '13 at 16:14

2 Answers2

3

use SoapHexBinary in namespace System.Runtime.Remoting.Metadata.W3cXsd2001

string s = "0x527AE53437CAED39D3E2A8B3E90FFC3BA9073B6D933BC05FF6677B5521DC34";
byte[] num = SoapHexBinary.Parse(s.Substring(2)).Value;
I4V
  • 34,891
  • 6
  • 67
  • 79
0

That string is hexadecimal.

If you want to convert it to a numeric you're going to need special handling - that's a very big number and will overflow the basic types.

If it was a reasonable size, all numeric types are agnostic of base-representation. To see a hexadecimal version of a number, you simply call .ToString("X") on it.

EDIT

My answer was based on the initial version of the question before the byte[] was specified. There is a previous SO question and answer for this: How can I convert a hex string to a byte array?

Community
  • 1
  • 1
Erik Noren
  • 4,279
  • 1
  • 23
  • 29