?
Solved

How do I read bytes in a file?

Posted on 2010-11-12
4
Medium Priority
?
989 Views
Last Modified: 2012-05-10
I have my file (it is a QDX file if anyone is familiar with that...) and I need to read the last 4 bits of the 559th byte in this file using vb.net or vbscript.  I've looked at a few other methods on here but can't get any of them to work.  Any help is appreciated!  Thanks
0
Comment
Question by:jasgiv1122
  • 3
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 34123065
Perhaps this?
Dim value As Short

Using source As New System.IO.FileStream("C:\file\path\file.qdx", IO.FileMode.Open)
	Dim target As Integer
	Dim mask As Short = 15

	source.Seek(559, IO.SeekOrigin.Begin)
	target = source.ReadByte()
	value = target And mask
End Using

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34123075
The offset probably needs to be 558 rather than 559.
0
 
LVL 2

Author Comment

by:jasgiv1122
ID: 34124163
This worked perfectly, thanks!  Can you explain the 'mask' part so I can sort of grasp what you did?  Thanks!
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34125044
The mask is for "and I need to read the last 4 bits". 15 in binary is 0000 1111, and when you AND that value with another value, you get the values of the last four bits.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question