• 0

[C#] Getting values from byte array?


Question

I have the following hex string:


010101030300000000000000000000000D00000001000000010000009050AA35B23BDA4B3532F2ABDF4A382E80100000014324686468645602538589053568950000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
[/CODE]

In hex editor it would look like this:

0ZTghjR.png

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

I have the following code:

[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);
[/CODE]

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

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.).

Link to comment
Share on other sites

  • 0

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);

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.