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 - byte[] buffer = new byte[52];
-
long addr = 5; (assuming I want to start to read from position 5
-
int count;
-
while ((count = stream.Read(buffer, addr, 52)) > 0)
This doesn't work. Please help
Thanks in advance.
3 2518
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... - byte[] buffer = <declare buffer>
-
long start = find <value> in buffer
-
for (long i = start; i < buffer.Length; i++)
-
{
-
// do something with buffer[i]
-
}
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
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.
Thanks for the feedback. This gave me some ideas how to proceed.
I find the following works though. - byte[] buffer = new byte[52];
-
int count;
-
int pos = 356;
-
stream.Seek(pos, SeekOrigin.Begin);
-
while ((count = stream.Read(buffer, 0, 52)) > 0)
-
{}
Sign in to post your reply or Sign up for a free account.
Similar topics
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?...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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++){...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |