exe to binary digit data string problem - 250 pts

hey guys, ive asked about this before, and its been slow getting responses... So i poked around, and i got alot closer. Here is my problem... I can read the exe file, and get the byte array, but when i convert it to string, it only shows the first number in the binary digit. Here is my code:

(***CODE***)
    Dim BinaryString As String
    Function BinaryToString(ByVal Binary As Array)
        'Antonin Foller, http://www.pstruh.cz
        'Optimized version of a simple BinaryToString algorithm.

        Dim cl1, cl2, cl3, pl1, pl2, pl3
        Dim L
        cl1 = 1
        cl2 = 1
        cl3 = 1
        L = Binary.Length

        Do While cl1 < L
            pl3 = pl3 & Chr(Asc(Binary(cl1))) & ","
            cl1 = cl1 + 1
            cl3 = cl3 + 1
            If cl3 > 300 Then
                pl2 = pl2 & pl3
                pl3 = ""
                cl3 = 1
                cl2 = cl2 + 1
                If cl2 > 200 Then
                    pl1 = pl1 & pl2
                    pl2 = ""
                    cl2 = 1
                End If
            End If
        Loop
        BinaryString = pl1 & pl2 & pl3
    End Function



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim BR As New IO.BinaryReader(IO.File.OpenRead(TextBox1.Text))
        Dim TheBytes(BR.BaseStream.Length) As Byte

        'BR.Read(TheBytes, 1, BR.BaseStream.Length)
        TheBytes = BR.ReadBytes(BR.BaseStream.Length)
        BinaryToString(TheBytes)
        TextBox2.Text = BinaryString

        'BR.Read(TheBytes, 1, BR.BaseStream.Length)
        'BinaryToString(TheBytes)
        'TextBox3.Text = BinaryString
    End Sub
End Class
(***END CODE***)

Now, when i run this, in txtbox1, i have the path to this program. When i click the button, the onclick event gets trigggered. It then reads the exe into a byte array, and converts it. Here is the output it gave me (well, the first 10 values):

7,9,6,1,5,0,2,0,3,0,

Here is the expected output (again, the first ten values):

77,90,68,1,5,0,2,0,32,0,

Now, you may have noticed my problem, the produced output, is different, in that it only displays one digit. The expected has many values that have 2 digits. The first digit in the produced o/p is the same as the first digit in the expected o/p. Now, i know this for sure, cause i went through the (litteraly thousands of) numbers outputted and compared.

Anyone wanna hint me as to why it is doing this? or gimme a fix for it?

***ALL my points going to this question, cause it is important***
Otis_04Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzzzzoocCommented:
>> pl3 = pl3 & Chr(Asc(Binary(cl1))) & ","

What is happening on that line is this:

cl1=0 (It starts from 1 in your example, but the first byte in the array is 0)

Binary(cl1)=90 (This is ASC() for "M" since VB applications start with "MZ")

Asc(Binary(cl1))=57 (Asc() returns the decimal (ascii) value for "90". Since it can only return the decimal for a single character, it returns the decimal for "9" (the first one))

Chr(Asc(Binary(cl1)))=9 (The previous returned the decimal for "9", Chr() returns the character of the ASCII decimal provided which is "57" which will return the character "9")


Modified example below.


Form1:
---------------------------------

Option Explicit

Public BinaryString As String
Private Sub BinaryToString(ByRef Binary() As Byte)
    Dim cl1, cl2, cl3, pl1, pl2, pl3, L
    cl1 = 1
    cl2 = 1
    cl3 = 1
    L = UBound(Binary) + 1
    Do While cl1 <= L
        pl3 = pl3 & Chr(Binary(cl1 - 1))
        cl1 = cl1 + 1
        cl3 = cl3 + 1
        If cl3 > 300 Then
            pl2 = pl2 & pl3
            pl3 = ""
            cl3 = 1
            cl2 = cl2 + 1
            If cl2 > 200 Then
                pl1 = pl1 & pl2
                pl2 = ""
                cl2 = 1
            End If
        End If
    Loop
    BinaryString = pl1 & pl2 & pl3
End Sub
Private Sub Form_Load()
    Dim iFF As Integer, bBuff() As Byte
    iFF = FreeFile
    Open "c:\Project1.exe" For Binary As iFF
        ReDim bBuff(LOF(iFF))
        Get #iFF, 1, bBuff()
    Close iFF
    Call BinaryToString(bBuff)
    Debug.Print BinaryString
End Sub
0
GrahamSkanRetiredCommented:
Don't  know why it's so complicated.

This does it in VB6

    Function BinaryToString(Arr() As String * 1) As String
    Dim i As Integer
    Dim Text As String
    Text = Asc(Arr(1))
    For i = 1 To UBound(Arr)
        Text = Text & ", " & Asc(Arr(i))
    Next i
    BinaryToString = Text
    End Function

0
GrahamSkanRetiredCommented:
Don't  know why it's so complicated.

This does it in VB6

    Function BinaryToString(Arr() As String * 1) As String
    Dim i As Integer
    Dim Text As String
    Text = Asc(Arr(1))
    For i = 1 To UBound(Arr)
        Text = Text & ", " & Asc(Arr(i))
    Next i
    BinaryToString = Text
    End Function

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

zzzzzoocCommented:
GrahamSkan, imagine dealing with 2MB binary files. With that example, you'll combine 1&2, 1&2&3, 1&2&3&4 and so forth. When you get above 1MB, there's alot of overhead on processing the combination of the large strings. It's the reason the function was done such as that.
0
Otis_04Author Commented:
yea. Ill take a look at that zzzzzooc, i think it will work :)
0
Otis_04Author Commented:
Did i mention i am using vb.NET ??

zzzzzooc - I replaced my binarytostring with yours and i get MZD[][]  (yes, those are boxes) It took me even further away from my results than i expected....
0
SiC_OCommented:
ok, Otis_04, i suggest you give up and try to do this in delphi. It would be alot easier...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GrahamSkanRetiredCommented:
Thanks zzzzzooc. I hadn't thought of that. We seem to have been using the wrong programming language anyway.
0
zzzzzoocCommented:
If you just wanted the ASC() values of the characters then they're already stored within the array.

Change pl3 = pl3 & Chr(Binary(cl1 - 1)) -----> pl3 = pl3 & Binary(cl1 - 1) & ","

I'm sure you can adjust the above for .NET.




Is there any reason you accepted the answer to use Delphi? I'd suggest ASM since it'll process faster for your scenario.

0
Otis_04Author Commented:
>Is there any reason you accepted the answer to use Delphi? I'd suggest ASM since it'll process >faster for your scenario.

I cant program in asm :( and i dont plan on learning it.
0
zzzzzoocCommented:
Well Delphi won't make a difference as VB can do just about the same. Not to mention the example for it was in VBScript. Just wondering why you accepted something that doesn't answer your question. I'd be fine if somebody provided an actual solution and it worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.