473,405 Members | 2,262 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,405 software developers and data experts.

Retrieving position of a byte within a Hex file using vb.net

Hello everyone,
I am trying to retrieve a byte within a hex document. I am looking for the position of 'R', which I have found but I need the hex value located 28 spaces before the position of 'R'. Here is the code I have been using to find the 'R' value:
Expand|Select|Wrap|Line Numbers
  1.          Dim byteRead As Byte
  2.           Dim j As Integer
  3.           For j = 0 To br.BaseStream.Length() - 1
  4.               byteRead = br.ReadByte
  5.               count = count + 1
  6.               If (byteRead = 82) Then
  7.                   bw.Write(byteRead)
  8.               End If
  9.           Next  
The loop searches for 82 (R) in a file and writes it to a file but I need to know what occurs at the position R-28. Any thoughts would be greatly appreciated.
Aug 7 '07 #1
4 1460
Plater
7,872 Expert 4TB
Read in the entire stream into a Byte[] first.
Then itterate through it's index looking for 'R'(82) then you will have an index number for it (say you called it IDX)
So if mybytearray[IDX]=='R' then you could say mybytearray[IDX-28] is the byte you want
Aug 7 '07 #2
Hi Plater,
I have tried that so many different ways but the syntax only clicked in my head when you posted your response. Everything works fine but considering the following code:
Expand|Select|Wrap|Line Numbers
  1.                                   Dim byteRead As Byte
  2.           Dim j As Integer
  3.           For j = 0 To br.BaseStream.Length() - 1
  4.               byteRead = br.ReadByte
  5.               bytes(j) = byteRead
  6.               count = count + 1
  7.               If (byteRead = 82) Then
  8.                   bw.Write(byteRead)
  9.               End If
  10.           Next
  11.  
  12.           For k = 0 To count
  13.               If (bytes(k) = 36) Then
  14.                   bv.Write(bytes(k - 28))
  15.               End If
  16.           Next
  17.  
I want to return the substring between k-28 to k-20, would I need a 2D array for this or is there any simpler way? Thanks again for the insight.
Aug 7 '07 #3
Plater
7,872 Expert 4TB
Well you have your array that is full of all the data.
And you know your start and stop points (count-28) - (count-20)

so do a for loop from the start spot to end spot and write the data where you want it
Aug 7 '07 #4
Thanks a lot. Most times I know what to do but I work all alone and it just takes someone it bounce it off from before I know the idea of what I need to do. Here is what i used just in case it may help out someone if they're in the same situation:
Expand|Select|Wrap|Line Numbers
  1.  For k = 0 To count
  2.               If (bytes(k) = 164) Then
  3.                   For z = -19 To -12
  4.                       bv.Write(bytes(k + z))
  5.                   Next
  6.               End If
  7.           Next 
Once again, thanks for giving me ideas!
Aug 7 '07 #5

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

Similar topics

8
by: Christopher Weaver | last post by:
I'm having the hardest time doing the simplest thing. I have a DataGrid bound to a table in a master detail DataRelation within a DataSet relTaskActivities = new DataRelation("TaskActivities",...
2
by: Senthil | last post by:
Hi, The need is to read each line in a text file and based on the read data decision has to be taken whether to reposition the file pointer. The StreamReader.Position does not give current...
6
by: Dean Slindee | last post by:
Does anybody have an actual example of retrieving an Image data type column from a SQL Server table using a dataset (not a datareader)? I would like to see the statements that would move the...
0
by: kid4rilla | last post by:
I can successfully write the binary data to an image data type, and successfully retrieve it, but when I attempt to play the file in media player after retrieving it, I get the file type isn't...
13
by: 010 010 | last post by:
I found this very odd and maybe someone can explain it to me. I was using fread to scan through a binary file and pull bytes out. In the middle of a while loop, for no reason that i could...
5
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are...
5
by: djhexx | last post by:
Hello. I have an ASP.NET application (C#) that I allow users to upload files. Files get stored in a SQL2005 database. The file data is stored in a varbinary(max) column. When the user uploads...
5
by: Sanjay Pais | last post by:
I have a table with over 1.3 million rows. I am retrieving only 20 at a time using the with - over clauses In query analyser, the data is retrieved in under a second. When retrieving using the...
0
by: velmani | last post by:
hi , i have problem with Retrieving image from DB i have a table with image datatype i store a file by using code as follows -------------------------------------------------- string strType; ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.