Advertisement
teplofizik

Helper.cs

Feb 14th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ArtNet.ArtNet
  7. {
  8.     static class Helper
  9.     {
  10.         static public void WriteString(ref byte[] Data, uint Offset, string Text, uint Length)
  11.         {
  12.             int i;
  13.  
  14.             for (i = 0; i < Length; i++)
  15.             {
  16.                 if (i < Text.Length)
  17.                 {
  18.                     Data[Offset + i] = Convert.ToByte(Text[i]);
  19.                 }
  20.                 else
  21.                 {
  22.                     Data[Offset + i] = 0;
  23.                 }
  24.             }
  25.  
  26.             // Пследний символ всегда 0
  27.             Data[Offset + Length - 1] = 0;
  28.         }
  29.  
  30.         static public void WriteArray(ref byte[] Data, uint Offset, byte[] Source, uint Length)
  31.         {
  32.             int i;
  33.  
  34.             for (i = 0; i < Length; i++)
  35.             {
  36.                 if (i < Source.Length)
  37.                 {
  38.                     Data[Offset + i] = Source[i];
  39.                 }
  40.                 else
  41.                 {
  42.                     Data[Offset + i] = 0;
  43.                 }
  44.             }
  45.         }
  46.  
  47.         // LB HB
  48.         static public void WriteUInt16(ref byte[] Data, uint Offset, int Value)
  49.         {
  50.             Data[Offset + 0] = Convert.ToByte(Value & 0xFF); // LSB
  51.             Data[Offset + 1] = Convert.ToByte((Value >> 8) & 0xFF); // MSB
  52.         }
  53.  
  54.         // HB LB
  55.         static public void WriteUInt16BE(ref byte[] Data, uint Offset, int Value)
  56.         {
  57.             Data[Offset + 1] = Convert.ToByte(Value & 0xFF); // LSB
  58.             Data[Offset + 0] = Convert.ToByte((Value >> 8) & 0xFF); // MSB
  59.         }
  60.  
  61.         static public void WriteByte(ref byte[] Data, uint Offset, byte Value)
  62.         {
  63.             Data[Offset] = Value;
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement