Results 1 to 5 of 5

Thread: Reading Bytes From File Endian

Threaded View

  1. #5
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: Reading Bytes From File Endian

    Just Create your own Converter, on any Integral data type you can call .ToString("X2") And It will pad the value so that it is 2 characters, for example if you have the integer value of 16 and you convert it with above tostring it becomes 0F, You can change the 2 with whatever number you need it padded to, or not spesify the number and it will use the default for the datatype.

    EDIT: For example
    Code:
        Function BytesToString(ByVal Buffer() As Byte) As String
            Dim st As New System.Text.StringBuilder(Buffer.Length * 2)
            For i = 0 To Buffer.Length - 1
                st.Append(Buffer(i).ToString("X"))
                If i <> Buffer.Length - 1 Then st.Append(" "c)
            Next
            Return st.ToString.Trim
        End Function
    EDIT:2 If you need to reverse the it you can use this
    Code:
    Function BytesToStringex(ByVal Buffer() As Byte) As String
            Dim st As New System.Text.StringBuilder(Buffer.Length * 2)
            For i = Buffer.Length - 1 To 0 Step -1
                st.Append(Buffer(i).ToString("X"))
                If i <> 0 Then st.Append(" "c)
            Next
            Return st.ToString
        End Function
    Last edited by BlindSniper; Dec 14th, 2011 at 02:25 PM.

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width