Jump to content



Photo

[C#] Getting values from byte array?


  • Please log in to reply
5 replies to this topic

#1 DPyro

DPyro

    Neowinian Senior

  • Joined: 11-December 05
  • Location: Ontario,Canada

Posted 04 May 2013 - 00:52

I have the following hex string:

010101030300000000000000000000000D00000001000000010000009050AA35B23BDA4B3532F2ABDF4A382E80100000014324686468645602538589053568950000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

In hex editor it would look like this:

Posted Image

I need to get the data at offset 0x1C - 0x2B (9050AA35B23BDA4B3532F2ABDF4A382E)

I have the following code:
byte[] data = ConvertHexStringToByteArray(Encoding.Default.GetString(hexstring));
MemoryStream input = new MemoryStream(data);
BinaryReader reader = new BinaryReader(input);
reader.ReadBytes(0x1C);
byte[] buffer = reader.ReadBytes(16);



#2 francescob

francescob

    Neowinian Senior

  • Tech Issues Solved: 1
  • Joined: 04-November 08

Posted 04 May 2013 - 01:05

doesn't that code already does what you need? or did I read the question wrong?

#3 OP DPyro

DPyro

    Neowinian Senior

  • Joined: 11-December 05
  • Location: Ontario,Canada

Posted 04 May 2013 - 01:07

doesn't that code already do what you need?

Yes and no. I get the data but need it as hex (9050AA35B23BDA4B3532F2ABDF4A382E) instead of ANSI (.Pª5²;ÚK52ò«ßJ8.).

#4 francescob

francescob

    Neowinian Senior

  • Tech Issues Solved: 1
  • Joined: 04-November 08

Posted 04 May 2013 - 01:12

Yes and no. I get the data but need it as hex (9050AA35B23BDA4B3532F2ABDF4A382E) instead of ANSI (.Pª5²;ÚK52ò«ßJ8.).

But what is the output type you need? A string or another byte array? Anyway if the input string is hex you just need to copy twice the bytes/characters from the original hex string to obtain the hex substring. Example: hexstring.SubString(0x1C * 2, 16 * 2);

#5 +Audien

Audien

    Software Eng.

  • Joined: 30-December 03
  • Location: Seattle, WA
  • OS: Windows 8.1/Mac OSX
  • Phone: iPhone 5S

Posted 04 May 2013 - 01:13

Is this what you want? Quick google.

http://stackoverflow...-and-vice-versa

#6 OP DPyro

DPyro

    Neowinian Senior

  • Joined: 11-December 05
  • Location: Ontario,Canada

Posted 04 May 2013 - 01:20

But what is the output type you need? A string or another byte array? Anyway if the input string is hex you just need to copy twice the bytes/characters from the original hex string to obtain the hex substring. Example: hexstring.SubString(0x1C * 2, 16 * 2);

This makes it way simpler, thanks.



Click here to login or here to register to remove this ad, it's free!