Guest User

Untitled

a guest
Jul 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace PinkbrainSilverlightApplication.Id3Reader.Util
  5. {
  6. public class Id3BinaryReader: BinaryReader
  7. {
  8. public Id3BinaryReader(Stream stream): base(stream)
  9. {
  10.  
  11. }
  12.  
  13. public UInt32 ReadUInt32FromUnsafeBigEndian()
  14. {
  15. byte[] unsafeUIntBytes = this.ReadBytes(4);
  16. byte[] correctedBytes = new byte[4];
  17.  
  18. correctedBytes[3] = (byte)(((unsafeUIntBytes[3] >> 0) & 0x7f) | ((unsafeUIntBytes[2] & 0x01) << 7));
  19. correctedBytes[2] = (byte)(((unsafeUIntBytes[2] >> 1) & 0x3f) | ((unsafeUIntBytes[1] & 0x03) << 6));
  20. correctedBytes[1] = (byte)(((unsafeUIntBytes[1] >> 2) & 0x1f) | ((unsafeUIntBytes[0] & 0x07) << 5));
  21. correctedBytes[0] = (byte)(((unsafeUIntBytes[0] >> 3) & 0x0f));
  22.  
  23. return (UInt32) ((correctedBytes[0] << 24) | (correctedBytes[1] << 16) | (correctedBytes[2] << 8) | correctedBytes[3]);
  24. }
  25. }
  26. }
Add Comment
Please, Sign In to add comment