473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

read certain position in hexadecimal

4
Hi C# experts
Said I have the following hexadecimal files
00000160h: 00 00 00 00 CD CD 00 30 39 21 03 50 00 02 0F 2E;
00000170h:
---

I need to read the bytes starting from CD.
I am not familiar with the offset buffer reading concept.
I tried to use this
Expand|Select|Wrap|Line Numbers
  1. byte[] buffer = new byte[52]; 
  2. long addr = 5; (assuming I want to start to read from position 5
  3. int count;
  4. while ((count = stream.Read(buffer, addr, 52)) > 0) 
This doesn't work. Please help

Thanks in advance.
Aug 28 '09 #1
3 2518
GaryTexmo
1,501 Expert 1GB
Well, buffer is just an array of bytes, so you should be able to access any valid index using the array index operator (ie, []). If you want to start at the first instance of CD you find, you should just be able to search through the buffer until you find it, then go from there. For example, some pseudo-code...

Expand|Select|Wrap|Line Numbers
  1. byte[] buffer = <declare buffer>
  2. long start = find <value> in buffer
  3. for (long i = start; i < buffer.Length; i++)
  4. {
  5.   // do something with buffer[i]
  6. }
Does that help at all? I'm not sure about your stream.Read code... if the above doesn't help you I'll look further into it, I'm just a bit pressed for time and thought I could sneak in some help before I had to run :D
Aug 28 '09 #2
tlhintoq
3,525 Expert 2GB
00 00 00 00 CD CD 00 30 39 21 03 50 00 02 0F 2E;
By the way, your bolded CD is in array position 4, not 5. Arrays are zero indexed.

[0] = 00
[1] = 00
[2] = 00
[3] = 00
[4] = CD

Have you tried simply reading all the bytes, then when you have it all in memory take what you want from it? Don't worry about an offset while reading. Take it all, then filter out what you don't want.
Aug 28 '09 #3
skkuan
4
Thanks for the feedback. This gave me some ideas how to proceed.
I find the following works though.
Expand|Select|Wrap|Line Numbers
  1.  byte[] buffer = new byte[52]; 
  2.  int count;
  3.  int pos = 356;
  4.  stream.Seek(pos, SeekOrigin.Begin);
  5.  while ((count = stream.Read(buffer, 0, 52)) > 0) 
  6. {}
Sep 1 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Shivani | last post by:
Hi, I am looking for a utility that reads hexadecimal numbers from a file into a string. The numbers in the file are seperated by "," as delimeter. Is there a standard C utility that can do that?...
1
by: Jordan | last post by:
I have a unicode XML file that I am trying to read using the .NET XmlTextReader in C#. How do I read the unicode file? If I try to using the XmlTextReader.Read() method, it throws an exception. ...
1
by: Michael Hodges | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en-us;815658 The page above solved all of my problems with one exception. When the file has strange data in it, possibly Japanese, I get the...
6
by: ataanis | last post by:
Hi, Can anybody tell me , why if I change the second value in the read() function, I get an error message, I'm dealing here with a file, that has at least 240 caracters per line Private Sub...
8
by: Vijay | last post by:
Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in...
2
by: Noel Mosa | last post by:
Hi, i have a file in memory in a char* string(which i read using buffered ifstreams from c++) and want to write a fake read() function for a C program that usually reads from files. What id...
23
by: ShaneO | last post by:
Hello, I wish to extract embedded string data from a file using a Binary Read method. The following code sample is used in VB.NET and similar code is used in VB6 - (Assume variable...
5
by: midhunmathe | last post by:
Hello, I get an error #', hexadecimal value 0x07, is an invalid character. Line 2, position 6358. on the XMLTextReader.Read() call on a particular node of my XML document. I need this data...
6
by: Andrea | last post by:
Hi, suppose that I have a string that is an hexadecimal number, in order to print this string I have to do: void print_hex(unsigned char *bs, unsigned int n){ int i; for (i=0;i<n;i++){...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.