Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Cannot convert int to system.iformatprovider

What I have tried:

textData = File.ReadAllBytes(@"C:\Users\Admin\Desktop\k1.txt");

           int[] intArray = new int[textData.Length];

           for (int i = 0; i < textData.Length; i++)
           {
               intArray[i] =Convert.ToInt16(textData[i],16);
           }
Posted
Updated 11-Oct-19 20:00pm
v2

1 solution

You seem to be trying to convert each byte to an integer, assuming that each byte contains a value between '0' and '9' inclusive.
If so, then this will do it:
int[] intArray = new int[textData.Length];

for (int i = 0; i < textData.Length; i++)
    {
    byte b = textData[i];
    if (b >= (byte)'0' && b <= (byte)'9')
        {
        intArray[i] = (int)(b - '0');
        }
    }
 
Share this answer
 
Comments
Member 14120682 12-Oct-19 2:05am    
im converting hex to decimal...can you tell that?
OriginalGriff 12-Oct-19 2:22am    
Then add the hex values as well:
for (int i = 0; i < textData.Length; i++)
    {
    byte b = textData[i];
    if (b >= (byte)'0' && b <= (byte)'9')
        {
        intArray[i] = (int)(b - '0');
        }
    if (b >= (byte)'A' && b <= (byte)'F')
        {
        intArray[i] = (int)((b - 'A') + 10);
        }
    }

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900