Re: Binary analysis tool 0.1
Well, there will probably be plenty of areas for code improvement, if nothing else.
I don't have the time to go through it thoroughly, but a couple of things jump out.
Rather than use the legacy Hex function, I think .Net mavens would prefer .Net method
Code:
' txtHex.Text = Hex(Convert.ToInt64(s, 2)).PadLeft(16, "0"c)
txtHex.Text = Convert.ToInt64(s, 2).ToString("X16")
That isn't a big deal.
A much bigger deal is that normally if you create an IDisposable item (e.g. a Pen, a Brush, a Graphics object, etc...) you should dispose of it when done.
You can dispose of it by calling the .Dispose method, or you can use "Using object As objectType" line when creating the object and "End Using" when done with it.
Code:
Dim blackBrush As New SolidBrush(Color.FromArgb(0, 0, 0))
For x As Integer = 0 To 7
g_bmSet.FillRectangle(blackBrush, x, y, 24, 24)
Next
blackBrush.Dispose
'===== or ======
Using blackBrush As New SolidBrush(Color.FromArgb(0, 0, 0))
For x As Integer = 0 To 7
g_bmSet.FillRectangle(blackBrush, x, y, 24, 24)
Next
End Using
You definitely shouldn't be creating disposable objects as a parameter to a method call, since you have no way to dispose of it yourself, and it is especially bad if that parameter is a method that is called in a loop.
In the code below, you have the potential to be creating that brush up to 65536 times.
Since the color doesn't change, if you have to create a brush it should be done outside the loop once, and the brush created used in the loop, as in the above example.
Code:
Private Sub HexToSet()
Dim i As Integer = 0
For set_y As Integer = 0 To 31
For set_x As Integer = 0 To 31
If i < lstHex.Items.Count Then
For y As Integer = 0 To 7
For x As Integer = 0 To 7
If Convert.ToString(Convert.ToInt64(lstHex.Items(i).ToString, 16), 2).PadLeft(64, "0"c).Substring(x + (y * 8), 1) = "1" Then
g_bmSet.FillRectangle(New SolidBrush(Color.FromArgb(0, 0, 0)), (set_x * 24) + (x * 3), (set_y * 24) + (y * 3), 3, 3)
End If
Next
Next
i += 1
End If
Next
Next
End Sub
Since creating a brush takes a bit of time, and properly disposing of the brush takes time, .Net provides already created pens and brushes for all the basic colors listed in the Colors properties so you can use them without having to create or dispose of them. I would change the code above to use the provided Black Brush, rather than create a black brush.
Code:
g_bmSet.FillRectangle(Brushes.Black, (set_x * 24) + (x * 3), (set_y * 24) + (y * 3), 3, 3)
Re: Binary analysis tool 0.1
Thanks for the corrections. I had some hard to find bugs, where after running the application a few times, it did not close properly. I think there is a possibility that not disposing might have been the cause of the problem. I will ask some additional questions regarding disposing of objects in the main forum.
I will post an updated version of the program with your recommendations, but I will not increment the version from 0.1, since I should not have numbered such a simple example anyway.