0

may should i post part of my code,and you check it and look what wrong????

0
private string BytesToHex(byte p)
        {
            throw new NotImplementedException();
        }
        // Function wo Convert Byte Array into String builder
        public static string BytesToHex(byte[] bytes)
        {
            StringBuilder hexString = new StringBuilder(bytes.Length);
            for (int i = 0; i < bytes.Length; i++)
            {

                hexString.Append(bytes[i].ToString("X2"));
                

            }
            return hexString.ToString();

        }
        

// Function who read to end Logfile and save it in Byte Array
        public static byte[] ReadFile(string filePath)
        {
            
            byte[] buffer;
            FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            try
            {
                int length = (int)fileStream.Length;  // get file length
                buffer = new byte[length];            // create buffer
                int count;                            // actual number of bytes read
                int sum = 0;                          // total number of bytes read

                // read until Read method returns 0 (end of the stream has been reached)
                while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
                    sum += count;  // sum is a buffer offset for next reading
                
                //for (int i = 0; i < fileStream.Length; i++)
                //{
                //    MessageBox.Show("Buffer[i] =" + i);
                //    MessageBox.Show(buffer[i].ToString());
                  
                   

                //}
                
            }   
            finally
            {
                fileStream.Close();
            }
            return buffer;


 private void button4_Click(object sender, EventArgs e)
        {
            try
            {

                //Creates a file with read-write access that allows others to read







                        System.IO.FileStream wFile;

                        
                        ////Initialisiert eine neue Instanz der FileStream-Klasse mit den Angaben für den Pfad, den Erstellungsmodus und die Freigabeberechtigung.
                        wFile = new FileStream(OpenFD.FileName, FileMode.Open, FileAccess.Read);
         
                         

                        string filePath = OpenFD.FileName;
                        //Liest einen Byteblock aus dem Stream und schreibt die Daten in einen angegebenen Puffer.
                        //int Bytes_Read = wFile.Read(My_Byte_Array, 0, NumBer_Of_bytes);
                        
                        for (int i = 0; i <= wFile.Length; i++)
                        {


                        //int [] Value = null;
                        ReadFile(filePath);
                        BytesToHex(ReadFile(filePath));
                        //int Value = (int)new System.ComponentModel.Int64Converter().ConvertFromString((BytesToHex((ReadFile(filePath)))));
                        int Value = int.Parse(BytesToHex(ReadFile(filePath)), System.Globalization.NumberStyles.HexNumber);

                        MessageBox.Show(BytesToHex(ReadFile(filePath)));
                        listBox1.Items.Add("Hex_Values[i] =" + (BytesToHex(ReadFile(filePath))[i].ToString()));
                       
                        int result;
                        //int[] a = null;
                        

                        
                        
                        //if (BytesToHex(ReadFile(filePath)) != null && BytesToHex(ReadFile(filePath)).StartsWith("0x") && int.TryParse((BytesToHex(ReadFile(filePath))).Substring(2), NumberStyles.AllowHexSpecifier, null, out result))
                        //{

                        //    result = int.Parse(BytesToHex(ReadFile(filePath)), NumberStyles.AllowHexSpecifier);
                        //    MessageBox.Show(result.ToString());
                           

                        //}
                        //listBox1.Items.Add(a[i].ToString());
                       // listBox1.Items.Add((BytesToHex(ReadFile(filePath))).ToString());
                       
                        ////MessageBox.Show(byteData[i].ToString());

                    }
                    
                    
                    //Liest ein Byte aus der Datei und erhöht die Leseposition um ein Byte
                   
                    //wFile.Close();
                    }

            catch (IOException ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }
0

use the following code to convert hexadecimal string to integer value

string val = "0010026AB0";
int inVal = System.Int32.Parse(val, System.Globalization.NumberStyles.AllowHexSpecifier);

Edited by abelLazm: n/a

Votes + Comments
Up voting by other accounts. You are lame
Helped me also
0

yes but it doesn´t help.th way i want to di is by click on Button 4 Convert the value of hexadecimal Stringbuilder in integer,but my compiler give my a failure back because the value in Stringbuiler ist too lang and can not be convert in integer,i want now a way to separe each value so that i will Convert it without problem. thx in advance

0

put this code in your program

private void button4_Click(object sender, EventArgs e)
{
try
            {

                //Creates a file with read-write access that allows others to read
               System.IO.FileStream wFile;
  wFile = new FileStream(OpenFD.FileName, FileMode.Open, FileAccess.Read);
            string filePath = OpenFD.FileName;
                        //Liest einen Byteblock aus dem Stream und schreibt die Daten in einen angegebenen Puffer.
                        //int Bytes_Read = wFile.Read(My_Byte_Array, 0, NumBer_Of_bytes);
                        listBox1.Items.Clear();
                        for (int i = 0; i <= wFile.Length; i++)
                        {
                            
                        //int [] Value = null;
                        ReadFile(filePath);
                        BytesToHex(ReadFile(filePath));
                        //int Value = (int)new System.ComponentModel.Int64Converter().ConvertFromString((BytesToHex((ReadFile(filePath)))));
                      //  int Value = int.Parse(BytesToHex(ReadFile(filePath)), System.Globalization.NumberStyles.HexNumber);

                        //MessageBox.Show(BytesToHex(ReadFile(filePath)));
                        int inVal = System.Int32.Parse(BytesToHex(ReadFile(filePath))[i].ToString(), System.Globalization.NumberStyles.AllowHexSpecifier);
                        listBox1.Items.Add(inVal.ToString());
                       
                        int result;
                        //int[] a = null;
                        
                        //if (BytesToHex(ReadFile(filePath)) != null && BytesToHex(ReadFile(filePath)).StartsWith("0x") && int.TryParse((BytesToHex(ReadFile(filePath))).Substring(2), NumberStyles.AllowHexSpecifier, null, out result))
                        //{

                        //    result = int.Parse(BytesToHex(ReadFile(filePath)), NumberStyles.AllowHexSpecifier);
                        //    MessageBox.Show(result.ToString());
                           

                        //}
                        //listBox1.Items.Add(a[i].ToString());
                       // listBox1.Items.Add((BytesToHex(ReadFile(filePath))).ToString());
                       
                        ////MessageBox.Show(byteData[i].ToString());

                    }
                    
                    
                    //Liest ein Byte aus der Datei und erhöht die Leseposition um ein Byte
                   
                    //wFile.Close();
                    }

            catch (IOException ex)
            {
                MessageBox.Show(ex.ToString());
            }
}
0

thank you did it good, wouldn't you have an idea on how to separate the values in the stringbuilder, and the separate ones out of bit of four, finally to be able to arise information hexadecimal after another???? something like.
Example
Byte = AA-BB , hexadecimale Value= 0xa3, integer Value = XXXX

0

this program is converting each byte array element at a time into hexadecimal and then into integer as far as your question is concerned you should check this condition when you read the file and if you current question is answered please mark this thread solved and start new thread for new question

0

may be you did not unterstand my question,i will try to formulate it better

0

Ok i hope now will be the best.
I have to read,and convert the Values of a binary Logfile save in my Computer als text Doc.
i have a Binary logfile,i have allready read all th byte in the text,and save it in a Buffer(big from 939 byte) ,now i read every Byte and convert it in Hexadecimalvalue,but in my logfile i have not only integer value,but Character too.That is why ,i need to have the value in this Format:

Example
byte[1] = AB-AA, Hexa_Value[1] = 0x0F, Integer_Value[1] = xx, character[1]= Mum,

Sorry,my English is worst,i hope you will understand the way i mean.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.