954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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.

AzraelUK
Newbie Poster
3 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

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.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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.

AzraelUK
Newbie Poster
3 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

Try this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = String.Empty
        Using fs As New FileStream("c:\test.txt", FileMode.Open)
            fs.Position = 0
            Using br As New BinaryReader(fs)
                For x As Int16 = 0 To 3
                    TextBox1.Text &= Asc(br.ReadChar) & " "
                Next
            End Using
        End Using
    End Sub
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

Hmm... Type 'FileStream' is not defined :/

AzraelUK
Newbie Poster
3 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

import System.IO

waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

hi i'm yasser from iraq i'm in the last year in computer science and i have project abaut the encryption on the mpeg file by using vb6 and i realy do not known any think about reading firt 4 byte from mpeg file i need your help and i must read this file by using open function

yasserjasem
Newbie Poster
1 post since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You