I have the need to convert a hex string into an integer using C#. I've tried all of the suggestions on SO including this one and many others. All of them throw the same or roughly the same... error. Value was either too large or too small for an Int32
(same for Int64
).
I can get the desired result in SQL Server 2008 with the following code:
select convert(int, 0x1B1D3E1B22176145272C1631282D221D30)
However THIS C# code
Int64.Parse("1B1D3E1B22176145272C1631282D221D30", NumberStyles.HexNumber)
Int32.Parse("1B1D3E1B22176145272C1631282D221D30", NumberStyles.HexNumber)
...yields the errors described above. Thoughts?? Solutions?
UPDATE: The SQL Code above yields the following integer.. 555949360. With every record I can find, the sql conversion yields a unique Integer. So the new question (I guess) is.. how to replicate the results of the SQL Convert function on this hex data?