DPyro Posted May 4, 2013 Share Posted May 4, 2013 I have the following hex string: 010101030300000000000000000000000D00000001000000010000009050AA35B23BDA4B3532F2ABDF4A382E80100000014324686468645602538589053568950000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000[/CODE] In hex editor it would look like this: 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 https://www.neowin.net/forum/topic/1150368-c-getting-values-from-byte-array/ Share on other sites More sharing options...
0 francescob Posted May 4, 2013 Share Posted May 4, 2013 doesn't that code already does what you need? or did I read the question wrong? Link to comment https://www.neowin.net/forum/topic/1150368-c-getting-values-from-byte-array/#findComment-595671484 Share on other sites More sharing options...
0 DPyro Posted May 4, 2013 Author Share Posted May 4, 2013 On 04/05/2013 at 01:05, francescob said: 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 https://www.neowin.net/forum/topic/1150368-c-getting-values-from-byte-array/#findComment-595671490 Share on other sites More sharing options...
0 francescob Posted May 4, 2013 Share Posted May 4, 2013 On 04/05/2013 at 01:07, DPyro said: 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 https://www.neowin.net/forum/topic/1150368-c-getting-values-from-byte-array/#findComment-595671496 Share on other sites More sharing options...
0 Argi Posted May 4, 2013 Share Posted May 4, 2013 Is this what you want? Quick google. http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa Link to comment https://www.neowin.net/forum/topic/1150368-c-getting-values-from-byte-array/#findComment-595671498 Share on other sites More sharing options...
0 DPyro Posted May 4, 2013 Author Share Posted May 4, 2013 On 04/05/2013 at 01:12, francescob said: 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 https://www.neowin.net/forum/topic/1150368-c-getting-values-from-byte-array/#findComment-595671510 Share on other sites More sharing options...
Question
DPyro
I have the following hex string:
In hex editor it would look like this:
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);
[/CODE]
Link to comment
https://www.neowin.net/forum/topic/1150368-c-getting-values-from-byte-array/Share on other sites
5 answers to this question
Recommended Posts