Reading the first four bytes of a (binary) files?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 3
Reputation: AzraelUK is an unknown quantity at this point 
Solved Threads: 0
AzraelUK AzraelUK is offline Offline
Newbie Poster

Reading the first four bytes of a (binary) files?

 
0
  #1
Sep 16th, 2007
Hi there, I was wondering if there was an easy way to read the first four bytes of a file. The ones in particular I'm looking for are 49 42 53 50 ("IBSP") and 46 42 53 50 ("FBSP"), but that bit should be easy.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Reading the first four bytes of a (binary) files?

 
0
  #2
Sep 16th, 2007
When you say bytes do you really mean the first four bytes or do you mean the first four numbes? I have a suspicion you mean the latter.
Last edited by iamthwee; Sep 16th, 2007 at 4:52 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 3
Reputation: AzraelUK is an unknown quantity at this point 
Solved Threads: 0
AzraelUK AzraelUK is offline Offline
Newbie Poster

Re: Reading the first four bytes of a (binary) files?

 
0
  #3
Sep 18th, 2007
Uhh... the first four hexadecimal numbers if you open the file in a hex editor. As I evidently didn't imply, when you open it in Notepad, the first four characters are either IBSP or FBSP.
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Reading the first four bytes of a (binary) files?

 
0
  #4
Sep 18th, 2007
Try this:
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. TextBox1.Text = String.Empty
  3. Using fs As New FileStream("c:\test.txt", FileMode.Open)
  4. fs.Position = 0
  5. Using br As New BinaryReader(fs)
  6. For x As Int16 = 0 To 3
  7. TextBox1.Text &= Asc(br.ReadChar) & " "
  8. Next
  9. End Using
  10. End Using
  11. End Sub
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 3
Reputation: AzraelUK is an unknown quantity at this point 
Solved Threads: 0
AzraelUK AzraelUK is offline Offline
Newbie Poster

Re: Reading the first four bytes of a (binary) files?

 
0
  #5
Sep 18th, 2007
Hmm... Type 'FileStream' is not defined :/
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Reading the first four bytes of a (binary) files?

 
0
  #6
Sep 18th, 2007
import System.IO
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC