binary to hex convertion?

03671328 used Ask the Experts™
ok so hears the deal I want to be able to read a file in form of hex as in the hex that a hex editor was displaying...

file w/ the fallowing hex
2B 00 25 01 00 14

will keep comming back as
43 0 37 1 0 20
after loading the file from binary...
any ideas?

rename to seeing it will not allow me to upload to site.

Dim myFileStream As FileStream
        Dim intByte As Integer
        Dim lngLoop As Long = 0
        Dim bteRead() As Byte
            myFileStream = File.OpenRead("C:\byte.dat")
            ReDim bteRead(myFileStream.Length)
            Do While Not intByte = -1
                intByte = myFileStream.ReadByte()
                If intByte <> -1 Then bteRead(lngLoop) = CByte(intByte)
                lngLoop += 1
                Dim bytDecimal As System.Byte = intByte
                Dim strHex As System.String = Hex(bytDecimal)
                Dim bytHex As System.Byte = "&H" & strHex
        Catch ex As IOException
        End Try
    End Sub

Open in new window
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Solution Analyst & Architect
Please try using the following code:

Dim bytAllBytes() As Byte = System.IO.File.ReadAllBytes("FILEPATH")
Dim strHex As String = String.Empty
For Each bytTemp As Byte In bytAllBytes
  'For your exact requirements
	strHex &= bytTemp.ToString("X2") & " "
  'however, you can use "X4" or "Xn" where replacing "n" with a numeric value will pad that number of zeros in the begining

Open in new window


Thank you that was exac`tly what i was looking for.

however i need to make sure there is a try in there just in case the file is not there eather way this is exactly what i needed I can add the rest. Thanks again.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial