Advertisement
tolikpunkoff

Header reading helpers for SxGeo

Sep 10th, 2018
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. private ushort ReadUShort(FileStream FST, bool revers)
  2. {
  3.     byte[] buf = ReadBytes(FST, 2);
  4.     if (buf == null) return 0;
  5.     if (revers) Array.Reverse(buf);
  6.     return BitConverter.ToUInt16(buf,0);
  7. }
  8.  
  9. private uint ReadUInt(FileStream FST, bool revers)
  10. {
  11.     byte[] buf = ReadBytes(FST, 4);
  12.     if (buf == null) return 0;
  13.     if (revers) Array.Reverse(buf);
  14.     return BitConverter.ToUInt32(buf, 0);
  15. }
  16.  
  17. private string BytesToString(byte[] bytes)
  18. {
  19.     //Преобразует массив байт в однобайтовую строку
  20.     // (1251, но для данных целей кодировка не важна)
  21.     if (bytes == null) return null;
  22.     return Encoding.GetEncoding(1251).GetString(bytes);
  23. }
  24.  
  25. private DateTime UnixTimeToDateTime(ulong UnixTime)
  26. {
  27.     DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0);
  28.     return origin.AddSeconds(UnixTime);
  29. }
  30.  
  31. private string GetVersion(byte ver)
  32. {
  33.     string v = ver.ToString();
  34.     if (ver < 10) return v;
  35.     v = v.Insert(v.Length - 1, ".");
  36.     return v;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement