Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Is it possible to convert the binary file to ASCII file?  (Read 30270 times)

0 Members and 1 Guest are viewing this topic.

vinoth124

    Topic Starter


    Rookie

    Is it possible to convert the binary file to ASCII file?
    « on: January 28, 2009, 03:53:16 AM »
    Hi Friend,

    Thanks in advance.

    Actually I need to convert a Binary file to Text file (ASCII file). Is it possible to convert it using DOS. If so please help to attain the same.

    Thanks,
    Vinoth R
     :)

    fireballs



      Apprentice

    • Code:Terminal
    • Thanked: 3
      Next time google it.

      vinoth124

        Topic Starter


        Rookie

        Re: Is it possible to convert the binary file to ASCII file?
        « Reply #2 on: January 28, 2009, 05:10:26 AM »
        I need a CODE to convert the file from Binary to ASCII formated file.... I dont want any tools to do it...,

        Thanks,
        Vinoth Rajagopal

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Is it possible to convert the binary file to ASCII file?
        « Reply #3 on: January 28, 2009, 05:24:41 AM »
        I need a CODE to convert the file from Binary to ASCII formated file.... I dont want any tools to do it...,

        Thanks,
        Vinoth Rajagopal

        that doesn't make any sense. Binary isn't a file format- it's a method of creating a file format. Word documents are binary. so are EXE images. So are a number of other formats... what kind of "Binary file" are you trying to convert to ASCII and what possible information could you glean from the ASCII result?


        If your looking to turn it into ASCII via HEX, a simple application to do so would load the file and write out the HEX equivalent of each byte.

        if your looking for CODE you should probably specify what kind of CODE you want. There is more then one type of CODE to do it in, and capitalizing CODE provides no benefit grammatically as I have just discovered.

        EDIT: also, we aren't here to do what might be homework for you; especially when the description is exceptionally vague.
        I was trying to dereference Null Pointers before it was cool.

        macdad-



          Expert

          Thanked: 40
          Re: Is it possible to convert the binary file to ASCII file?
          « Reply #4 on: January 28, 2009, 05:45:21 AM »
          well its pretty hard to do it in batch. you would need to learn binary and how to convert from binary to 32bit Integer and then convert that to its ASCII equivalent.

          VB would be needed for this kinda thing, since there are no user defined data types in batch.
          If you dont know DOS, you dont know Windows...

          Thats why Bill Gates created the Windows NT Family.

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: Is it possible to convert the binary file to ASCII file?
          « Reply #5 on: January 28, 2009, 06:45:42 AM »
          VB would be needed for this kinda thing, since there are no user defined data types in batch.

          you wouldn't need a UDT.

          Code: [Select]
          Private Function GetHiWord(dw As Long) As Integer
          If dw& And &H80000000 Then
             GetHiWord% = (dw& \ 65535) - 1
          Else
             GetHiWord% = dw& \ 65535
          End If
          End Function

          Private Function GetLoWord(dw As Long) As Integer
          If dw& And &H8000& Then
             GetLoWord% = &H8000 Or (dw& And &H7FFF&)
          Else
             GetLoWord% = dw& And &HFFFF&
          End If
          End Function

          Public Sub Binfile2Hexfile(ByVal InFile As String, ByVal Outfile As String)
          'Input: Any file.
          'Output: will create a file with each byte of Infile represented as a hexadecimal number.
          'Each byte is separated by a colon.
          'each line will contain 10 bytes worth of hex data.
          Dim fnIn As Integer, fnout As Integer
          'open both files.
          Dim longval As Long, longStr As String
          Dim tmpInt(1 To 2) As Integer, HexStr As String
          Dim AddColonCounter As Integer, BytesOnline As Integer
          fnIn = FreeFile
          Open InFile For Binary As fnIn
          fnout = FreeFile
          Open Outfile For Output As fnout

          Do Until EOF(fnIn)
              Get #fnIn, , longval
              longStr = ""
              'convert to a Hexadecimal string. Add necessary zeros to make it the proper size-
          ' in the case of a VB6 long variable, it's 8 bytes binary, but each byte is 2 bytes hex, so 16 characters.
              HexStr = Hex(longval)
              'Debug.Assert longval = 0
              If longval > 0 Then
                  longStr = String$(8 - Len(HexStr), "0") + Trim$(HexStr)
              Else
                  longStr = String$(8, "0")
              End If
              For AddColonCounter = 1 To 2
                  Mid$(longStr, (AddColonCounter * 2) + (AddColonCounter), 1) = ":"
              Next AddColonCounter
              Print #fnout, longStr;
              BytesOnline = BytesOnline + 1
              If BytesOnline = 10 Then
                  Print #fnout, vbCrLf
                  BytesOnline = 0
              End If
          Loop



          Close #fnout
          Close #fnIn




          End Sub

          *censored*, sometimes I forget all the experience I have with string manip routines. Haven't used the statement form of mid$ for a very long time... 8)
          I was trying to dereference Null Pointers before it was cool.

          macdad-



            Expert

            Thanked: 40
            Re: Is it possible to convert the binary file to ASCII file?
            « Reply #6 on: January 28, 2009, 09:35:18 AM »
            nicely done BC!  ;)
            kept getting errors with mine.
            If you dont know DOS, you dont know Windows...

            Thats why Bill Gates created the Windows NT Family.

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: Is it possible to convert the binary file to ASCII file?
            « Reply #7 on: January 28, 2009, 09:37:36 AM »
            took about 30 minutes. I was about to use a UDT and I realized that's what I was disproving  ::)

            So I just had to add in the low-word/hi-word functions, which I ended up not using anyway. interesting.
            I was trying to dereference Null Pointers before it was cool.