Question : How do I read an unsigned character in C#?

Hi,

I'm trying to use BinaryReader to read a binary file. While I can read unsigned shorts, I can't find a way to read an unsigned character type.

Is there a way to do this?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
using (BinaryReader br = new BinaryReader(File.Open(file, FileMode.Open, FileAccess.Read)))
            {
                long streamLength = br.BaseStream.Length;
                byte[] bytes = new byte[streamLength];

                try
                {
                    for (int i = 0; i < streamLength; i++)
                    {
                        bytes[i] = br.ReadByte();
                    }
                }

                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                finally
                {
                    ushort num;
                    ushort file;
                    char f;

                    num = BitConverter.ToUInt16(bytes, 0);
                    file = BitConverter.ToUInt16(bytes, 2);
                    f = BitConverter.ToChar(bytes, 53);
                    
                    Console.WriteLine(num);
                    Console.WriteLine(file);
                    Console.WriteLine(f);
                }
            }

Answer : How do I read an unsigned character in C#?

You don't need to convert.
"Byte" is actually an Unsigned 8-bit integer, which is more or less the same as C unsigned char
Random Solutions  
 
programming4us programming4us