Solved

How do I read bytes in a file?

Posted on 2010-11-12
4
947 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 75

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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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