binary to hex convertion?

03671328
03671328 used Ask the Experts™
on
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...

example
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 byte.zip to byte.data 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
 
        Try
            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
 
                MsgBox(bytHex)
 
            Loop
 
            myFileStream.Close()
 
        Catch ex As IOException
            Console.WriteLine(ex.Message)
        End Try
 
    End Sub

Open in new window

byte.zip
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Solution Analyst & Architect
Commented:
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
 
Next
 
MessageBox.Show(strHex)

Open in new window

Author

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