本文整理汇总了C#中System.Collections.BitArray.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.BitArray.CopyTo方法的具体用法?C# System.Collections.BitArray.CopyTo怎么用?C# System.Collections.BitArray.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.BitArray
的用法示例。
在下文中一共展示了System.Collections.BitArray.CopyTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button_update_Click
private void button_update_Click(object sender, EventArgs e)
{
System.Collections.BitArray bl, re, gr;
bl = new System.Collections.BitArray(bitsfield.Count / 3);
re = new System.Collections.BitArray(bitsfield.Count / 3);
gr = new System.Collections.BitArray(bitsfield.Count / 3);
Byte[] b = new Byte[resol * led_count / 8];
Byte[] r = new Byte[resol * led_count / 8];
Byte[] g = new Byte[resol * led_count / 8];
for (int i = 0; i < bitsfield.Count; i += 24)
{
for (int j = 0; j < 8; j++)
{
bl.Set(i / 3 + j, bitsfield.Get(i + (7 - j) * 3));
re.Set(i / 3 + j, bitsfield.Get(i + (7 - j) * 3 + 1));
gr.Set(i / 3 + j, bitsfield.Get(i + (7 - j) * 3 + 2));
}
}
bl.CopyTo(b, 0);
re.CopyTo(r, 0);
gr.CopyTo(g, 0);
String Bdata = "";
String Rdata = "";
String Gdata = "";
for (int i = 0; i < (resol * led_count / 8); i++)
{
Bdata += BitConverter.ToString(b, i, 1);
Rdata += BitConverter.ToString(r, i, 1);
Gdata += BitConverter.ToString(g, i, 1);
}
String txt = "";
for (int i = 0; i < (resol * led_count / 4); i += (led_count / 4))
{
txt += "0x";
txt += Bdata.Substring(i, (led_count / 4));
txt += ", 0x";
txt += Rdata.Substring(i, (led_count / 4));
txt += ", 0x";
txt += Gdata.Substring(i, (led_count / 4));
txt += ",\r\n";
}
this.textBox_data.Text = txt;
}
示例2: ReadingTask
void ReadingTask()
{
byte[] tempdata = new byte[data.Length];
while (true)
{
try
{
if (RTUDevice!=null && RTUDevice.connected != IsConnected)
{
IsConnected = RTUDevice.connected;
using( SecureDBEntities1 db = new SecureDBEntities1())
{
tblPDConfig pdc = db.tblPDConfig.Where(n => n.PDName == this.PDName).FirstOrDefault();
if (pdc != null)
{
pdc.Comm_state = IsConnected ? 1 : 0;
db.SaveChanges();
}
db.tblPDAlarmLog.Add(new tblPDAlarmLog() { Timestamp = DateTime.Now, PDItem = "Comm_state", PDName = this.PDName, Status = IsConnected ? 1 : 0 , UserMemo=pdc.Memo});
db.SaveChanges();
}
}
if (RTUDevice != null && RTUDevice.connected)
{
lock (lockobj)
{
RTUDevice.ReadDiscreteInputs(1, 0, 0, 12, ref tempdata);
if (tempdata == null)
{
Console.WriteLine(this.PDName + "讀取資料失敗");
reading_fail_cnt++;
continue;
}
else
reading_fail_cnt = 0;
if ((tblPDConfig.type ?? 1) == 2) //R11
{
for (int i = 0; i < tempdata.Length; i++)
tempdata[i] = (byte)(~tempdata[i]);
System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]);
System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata);
baryD.Set(0, baryS.Get(4)); //r0
baryD.Set(1, baryS.Get(5)); //s0
baryD.Set(2, baryS.Get(6)); // t0
baryD.Set(3, baryS.Get(0)); //r1
baryD.Set(4, baryS.Get(1)); //s1
baryD.Set(5, baryS.Get(2)); //t1
baryD.Set(6, baryS.Get(7)); // L0
baryD.Set(7, baryS.Get(8)); // L1
baryD.Set(8, baryS.Get(9)); // L2
baryD.Set(9, baryS.Get(10)); // L3
baryD.Set(10, baryS.Get(11)); // L4
baryD.Set(11, baryS.Get(3)); // cab
baryD.CopyTo(tempdata, 0);
}
else if((tblPDConfig.type ?? 1) == 7)
{
//for (int i = 0; i < tempdata.Length; i++)
// tempdata[i] = (byte)(~tempdata[i]);
System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]);
System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata);
baryD.Set(0, baryS.Get(4)); //r0
baryD.Set(1, baryS.Get(5)); //s0
baryD.Set(2, baryS.Get(6)); // t0
baryD.Set(3, baryS.Get(0)); //r1
baryD.Set(4, baryS.Get(1)); //s1
baryD.Set(5, baryS.Get(2)); //t1
baryD.Set(6, baryS.Get(7)); // L0
baryD.Set(7, baryS.Get(8)); // L1
baryD.Set(8, baryS.Get(9)); // L2
baryD.Set(9, baryS.Get(10)); // L3
baryD.Set(10, baryS.Get(11)); // L4
baryD.Set(11, !baryS.Get(3)); // cab
baryD.CopyTo(tempdata, 0);
}
else if ((tblPDConfig.type ?? 1) == 5) //R13
{
for (int i = 0; i < tempdata.Length; i++)
tempdata[i] = (byte)(~tempdata[i]);
System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]);
System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata);
baryD.Set(0, baryS.Get(4)); //r0
baryD.Set(1, baryS.Get(5)); //s0
baryD.Set(2, baryS.Get(6)); // t0
baryD.Set(3, baryS.Get(0)); //r1
baryD.Set(4, baryS.Get(1)); //s1
baryD.Set(5, baryS.Get(2)); //t1
baryD.Set(6, baryS.Get(7)); // L0
baryD.Set(7, baryS.Get(8)); // L1
baryD.Set(8, baryS.Get(9)); // L2
baryD.Set(9, baryS.Get(10)); // L3
//.........这里部分代码省略.........
示例3: Guild_ListPlayersInfo
public static void Guild_ListPlayersInfo(List<ObjData.guild_player> guildMembers, PacketWriter Writer)
{
Writer.Byte(guildMembers.Count);
foreach (ObjData.guild_player m in guildMembers)
{
Writer.DWord(m.MemberID);
Writer.Text(m.Name);
Writer.Byte(m.Rank);
Writer.Byte(m.Level);
Writer.DWord(m.DonateGP);
System.Collections.BitArray bits = new System.Collections.BitArray(new bool[]
{
m.noticeeditRight,
m.guildstorageRight,
m.unionRight,
m.withdrawRight,
m.joinRight,
false,false,false
});
byte[] bytes = new byte[1];
bits.CopyTo(bytes, 0);
Writer.DWord((int)bytes[0]);
Writer.DWord(0);
Writer.DWord(0);
Writer.DWord(0);
if (m.GrantName != null)
{
if (m.GrantName != "")
Writer.Text(m.GrantName);
else
Writer.Word(0);
}
else
Writer.Word(0);
Writer.DWord(m.Model);
Writer.Byte(m.FWrank);
Writer.Byte(m.Xsector);
Writer.Byte(m.Ysector);
Writer.DWord(0xFFFFFFFF); // when he entered last time 25794314
Writer.DWord(0x0189EECA); // when he leveled up last time 25816778 later :P
Writer.Bool(!m.Online);
}
}
示例4: ReceiveTask
static void ReceiveTask()
{
Stream stream=tcp.GetStream();
// int voltage=0;
// int data;
int voltage = 0, current = 0, mod1, mod2, mod3;
int AcFail=0,SmrWarning=0,major=0,minor=0;
byte[] data = new byte[32];
//while (true)
//{
//if (stream.Length == 32 )
//{
int cks = 0;
stream.Read(data, 0, 32);
Console.WriteLine("read");
voltage = data[1] + data[2] * 256;
current = data[3] + data[4]*256;
mod1=data[13];
mod2 = data[14];
mod3 = data[15];
AcFail = ((mod1 >> 6) & 1) ;
SmrWarning = ((mod1 >> 5) & 1) ;
major = ((mod1 >> 3) & 1) ;
minor = ((mod1 >> 4) & 1) ;
Console.WriteLine("v:{0} i:{1} mod1={2:X2} mod2={3:X2} mod3={4:X2} major:{5} minor:{6} Acfail:{7} SmrWarning:{8}", voltage, current, mod1, mod2, mod3,major,minor,AcFail,SmrWarning);
for (int i = 0; i < 32; i++)
{
cks+=data[i];
Console.Write("{0:X2} ",data[i]);
}
cks -= data[31];
Console.WriteLine();
if( (cks&255)!=data[31])
Console.WriteLine("cks error {0:X2}!",cks&255);
byte[] retData = new byte[6];
retData[0] = (byte)(voltage / 256);
retData[1] = (byte)(voltage % 256);
retData[2] = (byte)(current / 256);
retData[3] = (byte)(current % 256);
retData[4] = 0;
System.Collections.BitArray ba = new System.Collections.BitArray(new byte[] { 0 });
// bit 0 1 2 3
// major minor SmrWarning AcFail
ba.Set(0, major == 0);
ba.Set(1, minor == 0);
ba.Set(2, SmrWarning == 0);
ba.Set(3, AcFail == 0);
ba.CopyTo(retData, 5);
//for (int i = 0; i < 8; i++)
// stream.ReadByte();
//mod1 = stream.ReadByte();
//mod2 = stream.ReadByte();
//mod3 = stream.ReadByte();
}
示例5: getBrush
private Brush getBrush(int resPos, int ledPos)
{
System.Collections.BitArray bite = new System.Collections.BitArray(8);
byte[] bitref = new byte[1];
Brush br;
bite.Set(0, led_bits.Get(48 * resPos + 3 * ledPos));
bite.Set(1, led_bits.Get(48 * resPos + 3 * ledPos + 1));
bite.Set(2, led_bits.Get(48 * resPos + 3 * ledPos + 2));
bite.CopyTo(bitref, 0);
switch (bitref[0])
{
case 1:
br = br_blue;
break;
case 2:
br = br_red;
break;
case 3:
br = br_rb;
break;
case 4:
br = br_green;
break;
case 5:
br = br_gb;
break;
case 6:
br = br_rg;
break;
case 7:
br = br_rgb;
break;
default:
br = br_black;
break;
}
return br;
}
示例6: ReadingTask
void ReadingTask()
{
Stream stream=null;
// byte[] tempdata;// = new byte[34];
while (true)
{
try
{
if (tcp == null || !tcp.Connected)
{
// Comm_state = 0;
tcp = new TcpClient();
try
{
Console.WriteLine("Connect to Smr" + IP + ":" + Port);
tcp.Connect(IP, Port);
}
catch (Exception exx)
{
Console.WriteLine(exx.Message);
}
}
// 偵測 RTU開 斷線並產生事件
if (tcp != null && tcp.Connected)
{
Comm_state = 1;
stream = tcp.GetStream();
stream.ReadTimeout = 3000;
// int voltage=0;
// int data;
int voltage = 0, current = 0, mod1, mod2, mod3;
int AcFail = 0, SmrWarning = 0, major = 0, minor = 0;
byte[] rdata = new byte[32];
//while (true)
//{
//if (stream.Length == 32 )
//{
int cks = 0;
stream.Write(new byte[] { 0xaa, 0x02, 100, 2 + 100 }, 0, 4); // CSU 運作狀態 50d 32h
stream.Flush();
try
{
stream.Read(rdata, 0, 32);
}
catch (Exception ex)
{
Console.WriteLine("SMR_RTU"+ex.Message);
tcp.Close();
System.Threading.Thread.Sleep(1000);
continue;
}
Console.WriteLine("read");
voltage = rdata[1] + rdata[2] * 256;
current = rdata[3] + rdata[4] * 256;
mod1 = rdata[13];
mod2 = rdata[14];
mod3 = rdata[15];
AcFail = ((mod1 >> 6) & 1);
SmrWarning = ((mod1 >> 5) & 1);
major = ((mod1 >> 3) & 1);
minor = ((mod1 >> 4) & 1);
Console.WriteLine("v:{0} i:{1} mod1={2:X2} mod2={3:X2} mod3={4:X2} major:{5} minor:{6} Acfail:{7} SmrWarning:{8}", voltage, current, mod1, mod2, mod3, major, minor, AcFail, SmrWarning);
for (int i = 0; i < 32; i++)
{
cks += rdata[i];
Console.Write("{0:X2} ", rdata[i]);
}
cks -= rdata[31];
Console.WriteLine();
if ((cks & 255) != rdata[31])
Console.WriteLine("cks error {0:X2}!", cks & 255);
byte[] retData = new byte[6];
retData[0] = (byte)(voltage / 256);
retData[1] = (byte)(voltage % 256);
retData[2] = (byte)(current / 256);
retData[3] = (byte)(current % 256);
retData[4] = 0;
System.Collections.BitArray ba = new System.Collections.BitArray(new byte[] { 0 });
// bit 0 1 2 3
// major minor SmrWarning AcFail
ba.Set(0, major == 0);
ba.Set(1, minor == 0);
ba.Set(2, SmrWarning == 0);
ba.Set(3, AcFail == 0);
ba.CopyTo(retData, 5);
for (int i = 0; i < data.Length; i++)
data[i] = retData[i];
}
else
{
Comm_state = 0;
}
//.........这里部分代码省略.........
示例7: TableEntry
/// <summary>
/// Creates an object to hold a particular TableEntry.
/// </summary>
/// <param name="bytes">The bytes from which to make the TableEntry.</param>
public TableEntry(byte[] bytes)
{
System.Collections.BitArray ba = new System.Collections.BitArray(bytes);
Compressed = ba.Get(31);
ba.Set(31, false);
byte[] temp = new byte[4];
ba.CopyTo(temp, 0);
Offset = BitConverter.ToInt32(temp, 0);
}
示例8: NodeId
/// <summary>
/// Implements the operator >>,
/// </summary>
/// <param name="a">A.</param>
/// <param name="shift">The shift.</param>
/// <returns>The result of the operator.</returns>
public static NodeId operator >>(NodeId a, int shift)
{
if (((object)a == null) || shift == 0)
{
return a;
}
System.Collections.BitArray input = new System.Collections.BitArray(a.Data);
System.Collections.BitArray resultarray = new System.Collections.BitArray(a.Digits * 8);
byte[] result = new byte[a.Digits];
for (int i = a.Digits * 8 - 1; i >= a.Digits * 8 - 1 - shift; i--)
{
resultarray[i] = false;
}
for (int i = a.Digits * 8 - 1 - shift; i >= 0; i--)
{
resultarray.Set(i, input.Get(i + shift));
}
resultarray.CopyTo(result, 0);
Array.Reverse(result);
return new NodeId(result);
}
示例9: L
private byte[] L(byte[] state)
{
byte[] result = new byte[64];
for (int i = 0; i < 8; i++)
{
ulong t = 0;
byte[] tempArray = new byte[8];
Array.Copy(state, i * 8, tempArray, 0, 8);
tempArray = tempArray.Reverse().ToArray();
System.Collections.BitArray tempBits1 = new System.Collections.BitArray(tempArray);
bool[] tempBits=new bool[64];
tempBits1.CopyTo(tempBits, 0);
tempBits=tempBits.Reverse().ToArray();
for (int j = 0; j < 64; j++)
{
if (tempBits[j] != false)
t = t ^ A[j];
}
byte[] ResPart = BitConverter.GetBytes(t).Reverse().ToArray();
Array.Copy(ResPart, 0, result, i * 8, 8);
}
return result;
}