i have a file with ASCII as well as extended ASCII. I am unble convert this values to binary. Any help plzzz

i have a file with ASCII as well as extended ASCII. I am unble convert this values to binary. Any help plzzz

anywaz i solved the above prob.
i read the ascii value and wrote the decimal one in other file.
But values above "127" i.e. extended ascii are printed as 65533.
here ais wat i did:

private void button1_Click(object sender, EventArgs e)
            int[] b = new int[100000];
            StreamReader sw = new StreamReader("c: \\28D.09N");
            for (int i = 0; i < 5000; i++)
                b[i] = sw.Read();
                //int c = sw.Read();
                //int a = (int)c;
            /*SaveFileDialog sv = new SaveFileDialog();
            sv.Filter = "text file|*.txt";
            if (sv.ShowDialog() == DialogResult.OK)
                StreamWriter sr = new StreamWriter("c: \\bin28D.txt");
                for (int i = 0; i < 5000; i++)


any help for the extended ascii values plzzz

somebody reply plzzz.
i m not getting how to solve it 4 extended ascii

You have your "sr" and "sw" naming conventions reversed :D, but that is not your problem...

Your call to b[i] = sw.Read(); will only read a character at a time, which is why you cannot get the values you expect, presumably.

Look at the Read method spec and see if this helps. Otherwise, attach your input file so we can see how it is constructed.

EDIT: I think I misunderstood what you are doing. It is your intention to read each character and convert it to it's "decimal" equivalent? Just cast the return from Read to an unsigned int.

I looked at the file and it appears to be formatted, but I'm not sure what the format is. However, the question remains as to what you are trying to do as you are currently just reading in each character one at a time and storing it in your int[] , upto 5000 chars, then outputting the decimal equivalent of each of those chars. Is this intended?

actually i m reading the whole file and converting it into decimal value. The above code is just a demo. In real i have to read the whole file. I also conveerted some entended int values to ascii and save that file. next i read the same file and converted to int. its showing wrong values.

You have non-readable/printable characters in your input file. In c#, a "char" (Unicode representation) is 2 bytes, or 2^16, which has a max value of 65536. I'm not sure what it is you expect. You could force the output to be max byte length:


but, I don't know how that helps you or what you are trying to do...

Have a look at these articles:
Extended ASKII...