Solved

How do I read bytes in a file?

Posted on 2010-11-12
4
915 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 74

Accepted Solution

by:
käµfm³d   👽 earned 500 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 74

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 74

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now