Saved Bookmarks
| 1. |
Solve : Is it possible to convert the binary file to ASCII file?? |
|
Answer» Hi Friend, I need a CODE to convert the file from Binary to ASCII formated file.... I dont want any tools to do it..., 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.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.Quote from: macdad- on January 28, 2009, 05:45:21 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... nicely done BC! kept getting errors with mine. 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. |
|