本文整理汇总了C#中System.Collections.BitArray.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.CopyTo方法的具体用法?C# BitArray.CopyTo怎么用?C# BitArray.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.BitArray
的用法示例。
在下文中一共展示了BitArray.CopyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Mutate
/// <summary>
/// Mutates a gene by bitwise mutation.
/// </summary>
/// <param name="gene"></param>
/// <returns></returns>
public static Gene Mutate(Gene gene)
{
if ( gene is BinaryGene )
{
BinaryGene g = (BinaryGene) gene.Clone();
g.Value = !(BinaryGene)gene;
return g;
}
else if ( gene is DoubleGene )
{
DoubleGene g = (DoubleGene) gene.Clone();
byte[] bytes = BitConverter.GetBytes(g.Value);
BitArray ba = new BitArray(bytes);
int p = Utils.Rand.Next( ba.Length );
ba.Set(p, !ba[p]);
ba.CopyTo(bytes, 0);
g.Value = BitConverter.ToDouble(bytes,0);
return g;
}
else if ( gene is IntegerGene )
{
IntegerGene g = (IntegerGene) gene.Clone();
byte[] bytes = BitConverter.GetBytes(g.Value);
BitArray ba = new BitArray(bytes);
int p = Utils.Rand.Next( ba.Length );
ba.Set(p, !ba[p]);
ba.CopyTo(bytes, 0);
g.Value = BitConverter.ToInt32(bytes,0);
return g;
}
return (Gene) gene.Clone(); // default
}
示例2: verificarPermissao
public static bool verificarPermissao(Type tipoEntidadeVerificar, string chavePerfilCripto)
{
bool resultadoVerificacao = false;
BitArray arrayChaveDecripto = null;
byte[] preChavePerfilDecripto = new byte[ControladorAcesso.tamanhoChavePerfil];
bool[] chavePerfilDecripto = new bool[ControladorAcesso.tamanhoChavePerfil];
Criptografador cripto = new Criptografador();
preChavePerfilDecripto = cripto.decriptografarTexto(ref chavePerfilCripto);
arrayChaveDecripto = new BitArray(preChavePerfilDecripto);
arrayChaveDecripto.Length = ControladorAcesso.tamanhoChavePerfil;
arrayChaveDecripto.CopyTo(chavePerfilDecripto, 0);
foreach (object atributo in tipoEntidadeVerificar.GetCustomAttributes(true))
if (atributo.GetType().Name.Equals("PerfilAcesso"))
{
long CodigoPerfil = long.Parse(atributo.GetType().GetField("CodigoPerfil").
GetValue(atributo).ToString());
resultadoVerificacao = chavePerfilDecripto[CodigoPerfil];
break;
}
return resultadoVerificacao;
}
示例3: DecodeHiddenMessage
public AudioFile DecodeHiddenMessage(AudioFile containerAudioFile)
{
var hiddenBitsPerSample = containerAudioFile.waveFile.bitsPerSample / CHANGING_SAMPLES_FACTOR;
var hiddenMessageBits = new BitArray((int)(containerAudioFile.waveFile.samples.Length * hiddenBitsPerSample));
var maxNumberOfDecodingSteps = containerAudioFile.waveFile.samples.Length;
for (int i = 0; i < maxNumberOfDecodingSteps; i++)
{
var uintValue = containerAudioFile.waveFile.samples[i];
var intFromBitsToRead = uintValue.GetLastNBitsIntValue((int) hiddenBitsPerSample);
var hiddenIntBits = new BitArray(new[] { intFromBitsToRead }).GetBitArrayFromBitArrayRange(0, (int) hiddenBitsPerSample);
for(int j = 0; j < hiddenIntBits.Length; j++)
{
hiddenMessageBits.Set(i * (int) hiddenBitsPerSample + j, hiddenIntBits[j]);
}
}
containerAudioFile.waveFile.Save();
var messageBytes = new byte[hiddenMessageBits.Count];
hiddenMessageBits.CopyTo(messageBytes, 0);
return new AudioFile(containerAudioFile.bytes, messageBytes);
}
示例4: AppendBitArray
private static BitArray AppendBitArray(BitArray original, BitArray appended)
{
var bools = new bool[original.Count + appended.Count];
original.CopyTo(bools, 0);
appended.CopyTo(bools, original.Count);
return new BitArray(bools);
}
示例5: GetBoolArrayFromByte
public static bool[] GetBoolArrayFromByte(byte[] bytes)
{
bool[] bools = new bool[bytes.Length * 8];
BitArray bits = new BitArray(bytes);
bits.CopyTo(bools, 0);
return bools;
}
示例6: GenerateHeader
public static Byte[] GenerateHeader(Boolean fin, Boolean rsv1, Boolean rsv2, Boolean rsv3, Boolean opt4, Boolean opt3, Boolean opt2, Boolean opt1, Boolean mask)
{
Boolean[] header1 = new Boolean[8];
header1[7] = fin;
header1[6] = rsv1;
header1[5] = rsv2;
header1[4] = rsv3;
header1[3] = opt4;
header1[2] = opt3;
header1[1] = opt2;
header1[0] = opt1;
Boolean[] header2 = new Boolean[8];
header2[7] = mask;
header2[6] = false;
header2[5] = false;
header2[4] = false;
header2[3] = false;
header2[2] = false;
header2[1] = false;
header2[0] = false;
BitArray bitArray1 = new BitArray(header1);
Byte[] byteHead = new Byte[2];
bitArray1.CopyTo(byteHead, 0);
BitArray bitArray2 = new BitArray(header2);
bitArray2.CopyTo(byteHead, 1);
return byteHead;
}
示例7: ConvertToBitArray
private static bool[] ConvertToBitArray(int i)
{
BitArray b = new BitArray(new int[] { i });
bool[] bools = new bool[b.Length];
b.CopyTo(bools, 0);
return bools;
}
示例8: SerializeBitArray
/// <summary>
/// Serializes a BitArray into the writer.
/// </summary>
/// <param name="bitArray">The bit array</param>
/// <param name="writer">The primitive writer</param>
public static void SerializeBitArray(BitArray bitArray, IPrimitiveWriter writer)
{
// Write the byte length
if (bitArray == null)
{
writer.Write(byte.MaxValue); // byte.MaxValue represents null
return;
}
int currentByteLength = (bitArray.Count + 7) / 8;
if (currentByteLength >= byte.MaxValue)
{
throw new ArgumentException("BitArray is too big to be serialized.", "bitArray");
}
// Write the byte length
writer.Write((byte)currentByteLength);
// Write only if we need to
if (currentByteLength > 0)
{
// Copy the bitarray into a byte array
byte[] bitArrayBytes = new byte[currentByteLength];
bitArray.CopyTo(bitArrayBytes, 0);
// Serialize
writer.Write(bitArrayBytes);
}
}
示例9: WriteBitArray
public static void WriteBitArray(this BinaryWriter writer, BitArray buffer, int Len)
{
byte[] bufferarray = new byte[Convert.ToByte((buffer.Length + 8) / 8) + 1];
buffer.CopyTo(bufferarray, 0);
WriteBytes(writer, bufferarray.ToArray(), Len);
}
示例10: ConvertBitArrayToInt
private static int ConvertBitArrayToInt(bool[] bits)
{
BitArray b = new BitArray(bits);
int[] intArr = new int[1];
b.CopyTo(intArr, 0);
return intArr[0];
}
示例11: CopyBitArrayValueWise
public static BitArray CopyBitArrayValueWise(BitArray a)
{
bool[] bits = new bool[a.Count];
a.CopyTo(bits, 0);
return new BitArray(bits);
}
示例12: BinarySub
public int BinarySub(int a, int b)
{
bool Cin = false;
BitArray A = new BitArray(new int[] { a });
BitArray B = new BitArray(new int[] { b });
BitArray C = new BitArray(0);
A.Length = wordLength;
B.Length = wordLength;
C.Length = wordLength;
//Console.WriteLine("Subtracting " + a + " and " + b);
for (int i = 0; i < wordLength; i++)
{
myALU.SetInput("C", BoolToVolt(Cin));
myALU.SetInput("A", BoolToVolt(A[i]));
myALU.SetInput("B", BoolToVolt(B[i]));
myALU.UpdateOutputs();
C[i] = VoltToBool(myALU.GetOutput("SubResult"));
//Console.WriteLine(C[i] + " = " + A[i] + " + " + B[i]);
Cin = VoltToBool(myALU.GetOutput("SubCarry"));
}
int[] value = new int[1];
C.CopyTo(value, 0);
return value[0];
}
示例13: Setup
private void Setup()
{
// Fill Bit arrays
chka = new[] {
flag_0001,flag_0002,flag_0003,flag_0004,flag_0005,
flag_2237,flag_2238,flag_2239,
flag_0115,flag_0963, // Mewtwo
flag_0114,flag_0790, // Zygarde
flag_0285,flag_0286,flag_0287,flag_0288,flag_0289, // Statuettes
flag_0290,flag_0291,flag_0292,flag_0293,flag_0294, // Super Unlocks
flag_0675, // Chatelaine 50
flag_2546, // Pokedex
};
int offset = 0x1A0FC + savshift;
byte[] data = new byte[0x180];
Array.Copy(m_parent.savefile, offset, data, 0, 0x180);
BitArray BitRegion = new BitArray(data);
BitRegion.CopyTo(flags, 0);
// Setup Event Constant Editor
CB_Stats.Items.Clear();
for (int i = 0; i < 0x2FC; i += 2)
{
CB_Stats.Items.Add(String.Format("0x{0}", i.ToString("X3")));
Constants[i / 2] = BitConverter.ToUInt16(m_parent.savefile, 0x19E00 + i);
}
CB_Stats.SelectedIndex = 0;
// Populate Flags
setup = true;
popFlags();
}
示例14: GoPacketGo
private static void GoPacketGo(byte[] packet)
{
BitArray b = new BitArray(packet);
b[14] = b[0];
b[15] = b[1];
b[22] = b[2];
b[23] = b[3];
b[0] = b[1] = b[2] = b[3] = false;
b.CopyTo(packet, 0);
MousePacket p = new MousePacket();
p.DeltaX = 0x80 - (packet[1] ^ 0x80);
p.DeltaY = 0x80 - (packet[2] ^ 0x80);
//foreach (bool item in b)
//{
// Console.Write(item ? '1' : '0');
//}
//Console.WriteLine();
if (b[4])
p.PressedButtons |= ButtonState.RightButton;
if (b[5])
p.PressedButtons |= ButtonState.LeftButton;
if (b[29])
p.PressedButtons |= ButtonState.MiddleButton;
Console.WriteLine(p);
}
示例15: GetIntegerFromBitArray
public static int GetIntegerFromBitArray(bool[] input)
{
var result = new int[1];
var binary = new BitArray(input.Reverse().ToArray());
binary.CopyTo(result, 0);
return result[0];
}