BigEndianBinaryReader.cs 671 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.IO;
  3. namespace DvdLib
  4. {
  5. public class BigEndianBinaryReader : BinaryReader
  6. {
  7. public BigEndianBinaryReader(Stream input)
  8. : base(input)
  9. {
  10. }
  11. public override ushort ReadUInt16()
  12. {
  13. return BitConverter.ToUInt16(ReadAndReverseBytes(2), 0);
  14. }
  15. public override uint ReadUInt32()
  16. {
  17. return BitConverter.ToUInt32(ReadAndReverseBytes(4), 0);
  18. }
  19. private byte[] ReadAndReverseBytes(int count)
  20. {
  21. byte[] val = base.ReadBytes(count);
  22. Array.Reverse(val, 0, count);
  23. return val;
  24. }
  25. }
  26. }