CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 1999
    Posts
    43

    Convert a Binary File To Ascii String

    Dear All:

    I have a problem on converting a binary file to a Ascii String.
    The following is a sub to convert an input binary String to ascii string but I found that
    it does not working
    Can someone point out where did I do wrong???

    Thanks in advance


    public Sub Bin2Asc(strBin as string, strAsc as string)
    Dim lLen as Long, i as Long, strBin2 as string
    lLen = len(strBin)
    strAsc = ""
    for i = 1 to lLen
    Dim strTmp as string
    Dim btByte as Byte
    strTmp = Hex(Asc(mid$(strBin, i, 1)))
    If len(strTmp) < 2 then
    strTmp = "0" & strTmp
    else
    If len(strTmp) = 4 then
    lLen = lLen - 1
    End If
    strAsc = strAsc + strTmp
    If i = lLen then
    Exit for
    End If
    next i
    End Sub





  2. #2
    Guest

    Re: Convert a Binary File To Ascii String

    what you did wrong was that you used a ASCII->Binary function to convert Binary-> ASCII. The name of the function should have been Asc2Bin, because this will take any string and convert it to another string double the size containing the hex codes of all the chars.


  3. #3
    Join Date
    Jun 1999
    Posts
    43

    Re: Convert a Binary File To Ascii String

    Whoops!
    Sorry about the naming problem, this sub should call Asc2Bin.
    Assume I have a text file contain the follow hex value
    30 80 2A 86 48 86 F7 0D 01
    ^^^^^^^^^^^
    This sub will read all the hex value one by one collectly except it will read 2 byte at once for the &H8648 and &H86F7.

    I tried to use other conversion function like AscB.. etc, but they just doesn't work.
    Can someone give me a hint?

    Thanks in advance.


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

Featured