本文整理汇总了C#中BitArray.Set方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.Set方法的具体用法?C# BitArray.Set怎么用?C# BitArray.Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitArray
的用法示例。
在下文中一共展示了BitArray.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Set_InvalidIndex_ThrowsArgumentOutOfRangeException
public static void Set_InvalidIndex_ThrowsArgumentOutOfRangeException()
{
BitArray bitArray = new BitArray(4);
Assert.Throws<ArgumentOutOfRangeException>("index", () => bitArray.Set(-1, true));
Assert.Throws<ArgumentOutOfRangeException>("index", () => bitArray.Set(bitArray.Length, true));
Assert.Throws<ArgumentOutOfRangeException>("index", () => bitArray[-1] = true);
Assert.Throws<ArgumentOutOfRangeException>("index", () => bitArray[bitArray.Length] = true);
}
示例2: CapturedInput
/// <summary>
/// Initializes an CapturedInput with left, right, jump, and action keys.
/// </summary>
/// <param name="leftKey">If set to <c>true</c> left key is pressed.</param>
/// <param name="rightKey">If set to <c>true</c> right key is pressed.</param>
/// <param name="jumpKey">If set to <c>true</c> jump key is pressed.</param>
/// <param name="actionKey">If set to <c>true</c> action key is pressed.</param>
public CapturedInput(bool leftKey, bool rightKey, bool jumpKey)
{
inputArray = new BitArray(3);
inputArray.Set (0,leftKey);
inputArray.Set (1,rightKey);
inputArray.Set(2,jumpKey);
if ((leftKey || rightKey || jumpKey) == false)
{
this.empty = true;
}
else
this.empty = false;
}
示例3: renderCurrentState
private void renderCurrentState()
{
int i;
BitArray stacks = new BitArray( brain.getKnownObjects().Count );
foreach ( iThinkFact fact in brain.curState.getFactList() )
{
if ( fact.getName().Equals( "onTable" ) )
{
i = findNextFreeStack( stacks );
fact.getObj( 0 ).transform.position = new Vector3( (float)( 1.5 - i * 1.5 ), 0, 0 );
stacks.Set( i - 1, true );
}
}
foreach ( iThinkFact fact in brain.curState.getFactList() )
{
if ( fact.getName().Equals( "on" ) )
{
fact.getObj( 0 ).transform.position = fact.getObj( 1 ).transform.position;
fact.getObj( 0 ).transform.Translate( 0, (float)1.5, 0 );
}
else if ( fact.getName().Equals( "holding" ) )
{
fact.getObj( 0 ).transform.position = new Vector3( -15, 5, 0 );
}
}
}
示例4: Start
// Use this for initialization
void Start () {
playing = new BitArray(clips.Length);
playing.SetAll(false);
int clipId = getNextClipId();
asources[0].clip = clips[clipId];
asources[0].Play();
playing.Set(clipId, true);
playingCount = 1;
}
示例5: Set
/// <summary>
/// Sets the specified bit to true.
/// </summary>
/// <param name="bits">The BitArray to modify.</param>
/// <param name="index">The bit index to set to true.</param>
public static void Set(BitArray bits, System.Int32 index)
{
for (int increment = 0; index >= bits.Length; increment = +64)
{
bits.Length += increment;
}
bits.Set(index, true);
}
示例6: Get_Set
public static void Get_Set(bool[] newValues)
{
BitArray bitArray = new BitArray(newValues.Length, false);
for (int i = 0; i < newValues.Length; i++)
{
bitArray.Set(i, newValues[i]);
Assert.Equal(newValues[i], bitArray[i]);
Assert.Equal(newValues[i], bitArray.Get(i));
}
}
示例7: Start
// Use this for initialization
void Start()
{
//look for unique ID if not found generate one
if (PlayerPrefs.HasKey("caravan_pattern_UID") && PlayerPrefs.GetInt("caravan_pattern_UID") != 0){
pattern_UID = PlayerPrefs.GetInt("caravan_pattern_UID");
Debug.Log("found your own uniqe pattern: " + pattern_UID);
}
else{
BitArray bit_pattern = new BitArray(16);
for (int i = 0; i < 16; i++ ) {
bit_pattern.Set(i,Random.value > 0.5f);
}
PlayerPrefs.SetInt("caravan_pattern_UID",getIntFromBitArray(bit_pattern));
PlayerPrefs.Save();
pattern_UID = PlayerPrefs.GetInt("caravan_pattern_UID");
Debug.Log("generated your own uniqe pattern");
}
//create texture with pattern form playerprefs
pattern = new Texture2D((int)pattern_size.x * pixel_white.width,(int)pattern_size.y * pixel_white.height);
pattern.filterMode = FilterMode.Point;
//pattern.wrapMode = TextureWrapMode.Clamp;
BitArray pattern_array = new BitArray(System.BitConverter.GetBytes(pattern_UID));
Color[] pixels_white = pixel_white.GetPixels(0,0,pixel_white.width,pixel_white.height);
Color[] pixels_black = pixel_black.GetPixels(0,0,pixel_black.width,pixel_black.height);
int pixels_width = pixel_white.width;
int pixels_height = pixel_white.height;
for(int x = 0; x < pattern_size.x; x++){
for(int y = 0; y < pattern_size.y; y++){
if((pattern_array[(int)(x + (y*pattern_size.x))])){
pattern.SetPixels(x*pixels_width,y*pixels_height,pixels_width,pixels_height,pixels_white);
}
else{
pattern.SetPixels(x*pixels_width,y*pixels_height,pixels_width,pixels_height,pixels_black);
}
}
}
pattern.Apply();
renderer.material.SetTexture("_sign", pattern);
sign_material = (Material)Resources.Load("shader/sign_gui");
}
示例8: binaryStringToBytes
/* converts binary string to binary bytes */
public byte[] binaryStringToBytes(string _binaryString)
{
string binary = _binaryString;
int i = 0;
int j = 0;
BitArray bits = new BitArray(8);
byte[] bytes = new byte[binary.Length/8];
while (j!=binary.Length) {
for (i=0;i!=8;i++) {
bits.Set(i,(binary[j+i]=='1'?true:false));
}
bits.CopyTo(bytes,j/8);
j+=8;
}
return bytes;
}
示例9: runTest
public virtual bool runTest()
{
System.Console.Error.WriteLine( "BitArray- Co1555Get runTest started." );
int iCountErrors = 0;
int iCountTestcases = 0;
int i2 = -2;
bool b2 = false;
BitArray ba2 = null;
BitArray ba4 = null;
i2 = 6;
ba2 = new BitArray( i2 ,false );
ba2.Set( 0 ,true );
ba2.Set( 2 ,true );
ba2.Set( 5 ,true );
++iCountTestcases;
if ( ! ba2.Get( 0 ) )
{
++iCountErrors;
System.Console.Error.WriteLine( "Co1555Get Error E_545wi!" );
}
++iCountTestcases;
if ( ba2.Get( 1 ) )
{
++iCountErrors;
System.Console.Error.WriteLine( "Co1555Get Error E_319hf!" );
}
++iCountTestcases;
if ( ! ba2.Get( 2 ) )
{
++iCountErrors;
System.Console.Error.WriteLine( "Co1555Get Error E_063na!" );
}
++iCountTestcases;
if ( ba2.Get( 3 ) )
{
++iCountErrors;
System.Console.Error.WriteLine( "Co1555Get Error E_624cd!" );
}
++iCountTestcases;
if ( ! ba2.Get( 5 ) )
{
++iCountErrors;
System.Console.Error.WriteLine( "Co1555Get Error E_446xt!" );
}
try
{
++iCountTestcases;
ba2.Get( -3 );
++iCountErrors;
System.Console.Error.WriteLine( "Co1555Get Error E_876jv!" );
}
catch ( ArgumentException exc ) {}
catch (Exception ex)
{
++iCountErrors;
Console.Error.WriteLine( "Co1555Get Error E_643aw!" );
}
try
{
++iCountTestcases;
ba2.Get( (i2 + 3) );
++iCountErrors;
System.Console.Error.WriteLine( "Co1555Get Error E_748io!" );
}
catch ( ArgumentException exc ) {}
catch (Exception ex)
{
++iCountErrors;
Console.Error.WriteLine( "Co1555Get Error E_537aw!" );
}
i2 = 0x1000F;
ba2 = new BitArray( i2 ,false );
ba2.Set( 0 ,true );
ba2.Set( 2 ,true );
ba2.Set( 0x10001 ,true );
++iCountTestcases;
if ( ! ba2.Get( 2 ) )
{
++iCountErrors;
System.Console.Error.WriteLine( "Co1555Get Error E_333yy!" );
}
++iCountTestcases;
if ( ! ba2.Get( 0x10001 ) )
{
++iCountErrors;
System.Console.Error.WriteLine( "Co1555Get Error E_088ht!" );
}
if ( iCountErrors == 0 )
{
System.Console.Error.Write( "BitArray- Co1555Get: paSs. iCountTestcases==" );
System.Console.Error.WriteLine( iCountTestcases );
return true;
}
else
{
System.Console.Error.Write( "Co1555Get iCountErrors==" );
System.Console.Error.WriteLine( iCountErrors );
System.Console.Error.WriteLine( "BitArray- Co1555Get: FAiL!" );
return false;
}
//.........这里部分代码省略.........
示例10: GetData
public short GetData()
{
//try
//{
BitArray ba = new BitArray(16);
//Set all bits to 0
ba.SetAll(false);
/*
Left border 00000001
Right border 00000010
Top border 00000100
Bottom border 00001000
Inside borders 00010000
Outside borders 00100000
Autocolor 01000000 If this bit is set, the color index in bits 12 to 15 is not used.
*/
ba.Set(0, true); //this is always 0
#region WHICH BORDERS
if (_autocolor == true) ba.Set(1, true);
if (_outside == true) ba.Set(2, true);
if (_inside == true) ba.Set(3, true);
if (_bottom == true) ba.Set(4, true);
if (_top == true) ba.Set(5, true);
if (_right == true) ba.Set(6, true);
if (_left == true) ba.Set(7, true);
#endregion
#region BORDER STYLE
/*
0000 None
0001 3/4 point
0010 11/2 point
0011 21/4 point
0100 3 point
0101 41/2 point
0110 6 point
0111 3/4 point double
1000 11/2 point double
1001 21/4 point double
1010 3/4 point gray
1011 3/4 point gray dashed
*/
switch (_style)
{
case ParaBorderStyle.None:
ba.Set(8, false); ba.Set(9, false); ba.Set(10, false); ba.Set(11, false);
break;
case ParaBorderStyle.Point3_4:
ba.Set(8, false); ba.Set(9, false); ba.Set(10, false); ba.Set(11, true);
break;
case ParaBorderStyle.Point11_2:
ba.Set(8, false); ba.Set(9, false); ba.Set(10, true); ba.Set(11, false);
break;
case ParaBorderStyle.Point21_4:
ba.Set(8, false); ba.Set(9, false); ba.Set(10, true); ba.Set(11, true);
break;
case ParaBorderStyle.Point3:
ba.Set(8, false); ba.Set(9, true); ba.Set(10, false); ba.Set(11, false);
break;
case ParaBorderStyle.Point41_2:
ba.Set(8, false); ba.Set(9, true); ba.Set(10, false); ba.Set(11, true);
break;
case ParaBorderStyle.Point6:
ba.Set(8, false); ba.Set(9, true); ba.Set(10, true); ba.Set(11, false);
break;
case ParaBorderStyle.PointDouble3_4:
ba.Set(8, false); ba.Set(9, true); ba.Set(10, true); ba.Set(11, true);
break;
case ParaBorderStyle.PointDouble11_2:
ba.Set(8, true); ba.Set(9, false); ba.Set(10, false); ba.Set(11, false);
break;
case ParaBorderStyle.PointDouble21_4:
ba.Set(8, true); ba.Set(9, false); ba.Set(10, false); ba.Set(11, true);
break;
case ParaBorderStyle.PointGray3_4:
ba.Set(8, true); ba.Set(9, false); ba.Set(10, true); ba.Set(11, false);
break;
case ParaBorderStyle.PointGrayDashed3_4:
ba.Set(8, true); ba.Set(9, false); ba.Set(10, true); ba.Set(11, true);
break;
default: // no borders
ba.Set(8, false); ba.Set(9, false); ba.Set(10, false); ba.Set(11, false);
break;
}
#endregion
#region BORDER COLOR
/*
0000 Black
0001 Blue
0010 Cyan
0011 Green
0100 Magenta
0101 Red
0110 Yellow
//.........这里部分代码省略.........
示例11: Decode
/*
* Decodes received data (checks for validity, corrects network order, etc.).
*
* receive: The bytes received from the server.
* carry: Bits that are being carried over from a previous packet.
*
* return: A Decode object with decoded data or null if packet is too corrupt.
*/
static byte[] Decode(byte[] receive)
{
int readcnt = 0;
int readlen = (receive.Length-4) * 8; // Bytes of data -> bits.
readlen -= (readlen / 32) * 6; // Each 32 bits has 6 parity bits.
readlen -= (new int[] { 0, 4, 5, 5 })[receive.Length % 4]; // Parity bits for smaller packets.
BitArray read = new BitArray(readlen);
// Loop through each 32 bit packet after the first 32 bit header.
for ( int i = 4; i < receive.Length; ) {
int size = receive.Length - i;
if ( size > 4 ) size = 4; // Packet is between 1 and 4 bytes.
BitArray[] data = new BitArray[size];
for ( int e = size - 1; e >= 0; e-- ) // Copy out the bytes in reverse order.
data[e] = Reversed(receive[i++]); // Reverse the bits too.
bool even;
int badloc = -1;
BitArray bits = Reversed(ToBits(data)); // Read in the bits.
// Iterate through parity values (1, 2, 4, 8, ...), but skip the last parity.
for ( int p = 1; p < bits.Length-1; p *= 2 ) {
even = ! bits.Get(p-1); // Even state is the opposite of the parity bit.
// Iterate through starting points for take positions.
for ( int l = p-1; l < bits.Length; l += p)
// Iterate through take values.
for ( int e = 0; e < p && l < bits.Length; e++, l++ )
// Check if take value is a parity bit.
if ( Math.Log(l+1, 2) % 1 != 0 )
even ^= bits.Get(l); // Flip bit if 1.
if ( ! even ) badloc += p; // Bad bit = sum of failed parity values.
}
// Flip the bad bit if necessary.
if ( badloc >= 0 ) bits.Set(badloc, ! bits.Get(badloc));
even = true; // Run the checksum over the full packet.
foreach ( bool bit in bits ) even ^= bit;
if ( ! even ) return null; // Packet cant be fixed.
// Extract parity bits.
for ( int lb = bits.Length; lb > 0; lb-- )
if ( Math.Log(lb, 2) % 1 != 0 )
read.Set(readcnt++, bits.Get(lb-1));
}
// Allocate a byte array space equal to the number of bytes read.
byte[] bytes;
if ( readlen % 8 == 0 )
bytes = new byte[(readlen / 8)];
else
bytes = new byte[(readlen / 8) + (8 - readlen % 8)];
read.CopyTo(bytes, 0);
// Last block (block less than max size, 516), eliminate trailing nulls.
if ( receive.Length < 516 ) {
int size = bytes.Length;
for ( ; size > 0 && bytes[size-1] == 0; size-- );
byte[] trimmed = new byte[size];
for ( int i = 0; i < size; i++ ) trimmed[i] = bytes[i];
bytes = trimmed;
}
return bytes;
}
示例12: ShiftLeft
// returns the bit array shifted a specified number of bits to the left
public static BitArray ShiftLeft(BitArray bitboard, int shift)
{
BitArray shiftedBitBoard = new BitArray(bitboard.Length, false);
for (int i = bitboard.Length - 1; (i - shift) >= 0; i--)
{
shiftedBitBoard.Set((i - shift), bitboard.Get(i));
}
return shiftedBitBoard;
}
示例13: Reversed
// Reverse a bit array.
static BitArray Reversed(BitArray bits)
{
int loc = bits.Length - 1;
BitArray newbits = new BitArray(bits.Length);
foreach ( bool bit in bits ) newbits.Set(loc--, bit);
return newbits;
}
示例14: ToBits
// Flatten a bits array.
static BitArray ToBits(BitArray[] bits)
{
int size = 0;
foreach ( BitArray bitz in bits ) size += bitz.Length;
int loc = 0;
BitArray newbits = new BitArray(size);
foreach ( BitArray bitz in bits )
foreach ( bool bit in bitz )
newbits.Set(loc++, bit);
return newbits;
}
示例15: GetWalkingSteps
public static LinkedList<Point> GetWalkingSteps(Point start, BitArray goals, bool walkInWater = false, bool nearbyOk = false)
{
Bb.ReadBoard();
if (!goals.ToPoints().Any())
{
return null;
}
Point[] starts = { start };
var passable = Solver.GetPassable(true);
var aStarPassable = new BitArray(passable);
aStarPassable.Set(start, true);
if (nearbyOk)
{
aStarPassable.Or(goals);
}
Func<Point, Point, int> cost = (c, n) => (Bb.Water.Get(n) && !walkInWater) ? 10 : 1;
var route = Pather.AStar(starts, p => goals.Get(p), aStarPassable, cost, p => 0);
if (route == null)
{
return null;
}
var steps = new LinkedList<Point>(route);
steps.RemoveFirst();
if (steps.Count > 0 && !passable.Get(steps.Last.Value))
{
steps.RemoveLast();
}
return steps;
}