2

I have Binary(16) column in table 'Chip' with value 0xE1FC2E6F8674B7B9045C1104F9124C48 and in another table i have column chip_i which is type of integer that has the same value (but in int) = -116241336. Im using SQL Server 2012.

How can i convert 0xE1FC2E6F8674B7B9045C1104F9124C48 to -116241336 in C#?

I tried to convert it like this:

  string hexString = "0xE1FC2E6F8674B7B9045C1104F9124C48";
  byte[] hexByte = Encoding.ASCII.GetBytes(hexString);
  var chip_i = BitConverter.ToInt32(hexByte, 0);

but the result is 826636336

1 Answer 1

3

-116241336 is simply the last 4 bytes treated as a raw little-endian integer; 0xF9124C48. So: just use the last 4 bytes as is. No need for ASCII:

int chip_i = Convert.ToInt32(hexString.Substring(hexString.Length - 8, 8), 16);
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.