Byte.cs 841 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. namespace S7.Net.Types
  3. {
  4. /// <summary>
  5. /// Contains the methods to convert from bytes to byte arrays
  6. /// </summary>
  7. public static class Byte
  8. {
  9. /// <summary>
  10. /// Converts a byte to byte array
  11. /// </summary>
  12. public static byte[] ToByteArray(byte value)
  13. {
  14. return new byte[] { value }; ;
  15. }
  16. /// <summary>
  17. /// Converts a byte array to byte
  18. /// </summary>
  19. /// <param name="bytes"></param>
  20. /// <returns></returns>
  21. public static byte FromByteArray(byte[] bytes)
  22. {
  23. if (bytes.Length != 1)
  24. {
  25. throw new ArgumentException("Wrong number of bytes. Bytes array must contain 1 bytes.");
  26. }
  27. return bytes[0];
  28. }
  29. }
  30. }