Hi!! again i have a problem here ,,,,i have hexadecimal saved in file...now i want ....  
Author Message
syhzaidi





PostPosted: Visual C# Language, Hi!! again i have a problem here ,,,,i have hexadecimal saved in file...now i want .... Top

Hi..

now plz read carefully......i have a hexadecimal text file.such as file.txt saved on disk.....

so format of the hexadecimal stored is.....1a 2a 14 01 3d 23 45 12 2c 1c 3a

remember there is space between every hexadecimal ..

i want to read this file of hexadecimal as follows:

i want the when this file is read ,,first it should be stored in array

see follows example.

array[0] = 1a2a , array[1] = 1401 , array [2] = 3d23 ,array[3] = 4512, array [4] = 2c1c....

very important see that at every array position u have read two hexa decimals...at one array position stored it,,,

now these hexa decimal has been read from file and stored in a array,,,,

seconldy i want that array should be of integer,,,means the above hexadecimal should be converted in decimal ...example see below.....

array[0] = 6698 , array [1] = 5121 , array[2] = 15651, array[3] = 17682 , array[4] =11292......

so above the hexadecimal has been converted into decimal and stored in an array of integers....at one position..(very important).....therefore....there should be two array i think one of integers and other of strings.....well i have work hard but could do it...plz help me




Visual C#10  
 
 
Markku Behm





PostPosted: Visual C# Language, Hi!! again i have a problem here ,,,,i have hexadecimal saved in file...now i want .... Top

Hi

Hope this help you.

FileStream stream = new FileStream(p, FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader reader = new StreamReader(stream);
string str = reader.ReadToEnd();
string[] strs = str.Split(new char[] { ' ' });
List<int> nums = new List<int>();
for (int i = 0; i < strs.Length - 1; )
{
int a = int.Parse(strs[i++] + strs[i++], NumberStyles.HexNumber);
nums.Add(a);
}
int[] array = nums.ToArray();

Note that this code don't check how meny hex numbers (strs.Length) there is. Is there even quantity of numbers and if isn't what we do then

Yours Markku


 
 
syhzaidi





PostPosted: Visual C# Language, Hi!! again i have a problem here ,,,,i have hexadecimal saved in file...now i want .... Top

hi

well this codes runs good thx for it but the problem arrives how to print array of strings ....such as array [0] = 1a2a,,,it print and only integers.....and for length well it is not even.....i have used array.length for it to print array of integers



 
 
Markku Behm





PostPosted: Visual C# Language, Hi!! again i have a problem here ,,,,i have hexadecimal saved in file...now i want .... Top

So, is this what you looking for:

FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader reader = new StreamReader(stream);
string str = reader.ReadToEnd();
string[] strs = str.Split(new char[] { ' ' });
List<string> strings = new List<string>(); // new line
List<int> nums = new List<int>();
for (int i = 0; i < strs.Length - 1;)
{
strings.Add(strsIdea + strs[i + 1]); // new line
int a = int.Parse(strs[i++] + strs[i++], NumberStyles.HexNumber);
nums.Add(a);
}
int[] intArray = nums.ToArray();
string[] stringArray = strings.ToArray(); // new line

Markku