HexCounter






4.78/5 (6 votes)
HexCounter, Calculate the number HEX duplicate
- Download hex (RAR) - 38.3 KB
- Download hex (ZIP) - 38.2 KB
- Download Debug (RAR) - 16.1 KB
- Download Debug (ZIP) - 16.8 KB
- Download hexcalculate (ZIP) - 19.7 KB
Introduction
Hex Counter code to calculate the number of characters duplicate.
Background
The program for the identification of duplicate code (2 bytes) and build a compression algorithm written.
It can quickly read hex numbers and count the number of duplicates. It may be useful to you.
Using the Code
Call all void
in button with openFileDialog
:
// openFileDialog1=ofd
ofd.Title = "Hex";
//filter file
ofd.Filter = "Text Normal|*.txt|Text INF|*.inf";
if (ofd.ShowDialog() != DialogResult.Cancel)
{
// start timer for check speed program option
Benchmark.Start();
//call void read file
Load_file(ofd.FileName, listBox1, true); //set address
Counter_hex(listBox1, listBox2); //counter hex
//add_index(listBox1); // add list index option
//button2.Enabled = false; // control button off just one click
Benchmark.End(); //end timer
double seconds = Benchmark.GetSeconds(); //calculate time run void
MessageBox.Show(seconds.ToString());
}
Calculate hex and add to list:
public void Counter_hex(ListBox list1, ListBox list2)
{
_temp = list1.Items[0].ToString(); //get first hex
int _temp2 = 1; //base start
for (int h = 1; h <= list1.Items.Count - 1; h++) // star main loop
{
for (int i = 0; i <= list1.Items.Count - 1; i++) //find duplicate hex
{
//counter hex
if (_temp == list1.Items[i].ToString())
{
_temp2++;
}
}
// add to list with position (if sort=true)
list2.Items.Add(_temp + "=" + ((_temp2 - h)).ToString() +
"|" + _temp2.ToString() + "-" + h.ToString());
if (_temp2 < list1.Items.Count)
{
int b = _temp2;
_temp = list1.Items[b].ToString();
}
//jumper to other hex
h = _temp2 - 1;
}
}
Load File with FileStream
and BinaryReader
:
I use ListBox
for sample, but you can use:
List<string> list = new List<string>; // it is more effective
</string>
private void Load_file(string Address_file,ListBox add,bool sort)
{
FileStream magic = new FileStream(Address_file,FileMode.Open,FileAccess.Read);
BinaryReader magic2 = new BinaryReader(magic);
int _length = (int) magic.Length;
for (int i = 0; i <= _length - 2; i++)
{
//3 way i tested for speed reading with array[]
//add.Items.Add(cp[i].ToString() + cp[i+1].ToString()); //(char)
// add.Items.Add(Convert.ToChar(magic2.Read()).ToString());
//add.Items.Add(Convert.ToChar(magic2.Read()).ToString() + Convert.ToChar(magic2.PeekChar()));
add.Items.Add((char)(magic2.Read()) + Convert.ToChar(magic2.PeekChar()).ToString());
i++;
}
// sorted text option
if (sort==true)
{
add.Sorted = true;
}
}