1

How to read uint8 from binary file? From BinaryReader tried already ReadUint16/32 not working for this And uchart too, cant find way to read these two. Any ideas?

Rhonin
  • 474
  • 4
  • 20

1 Answers1

0

C#'s implementation of "uint8" is Byte, while "int8" is SByte.

BinaryReader has a ReadByte() method to read bytes.

BinaryReader also has a ReadChar() method.

Getting familiar with a language/framework's documention is a key skill to develop. In this case, MSDN C#.

Jecoms
  • 2,558
  • 4
  • 20
  • 31
  • When I use ReadByte to read uint8, then how to convert to int of C#? I assume its int32 and could use BitConverter.ToInt32 but I dont realy know to use it – Rhonin Nov 23 '16 at 19:12
  • Just assign the byte to an int variable. You can't lose data when moving to a larger integer type. – Jecoms Nov 23 '16 at 19:15
  • Is it possible that if I have file in little endian need to read or do something else more? becouse cant read properly file :( – Rhonin Nov 23 '16 at 20:20
  • `BitConverter.IsLittleEndian` will indicate which endianness is used by your system. If the file doesn't match the system's endianness, then you'd need to convert the bytes from the file to the system's endianness before assigning the byte values to an int. – Jecoms Nov 23 '16 at 20:33
  • Had to add Encoding.ASCII to BinaryReader as option, now its working fine :) thx for help – Rhonin Nov 27 '16 at 09:40