You've already forked linux-packaging-mono
Imported Upstream version 4.2.0.179
Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
committed by
Jo Shields
parent
aa7da660d6
commit
c042cd0c52
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.Serialization
|
||||
{
|
||||
class BitFlagsGenerator
|
||||
{
|
||||
int bitCount;
|
||||
byte [] locals;
|
||||
|
||||
public BitFlagsGenerator (int bitCount)
|
||||
{
|
||||
this.bitCount = bitCount;
|
||||
int localCount = (bitCount+7)/8;
|
||||
locals = new byte [localCount];
|
||||
}
|
||||
|
||||
public void Store (int bitIndex, bool value)
|
||||
{
|
||||
if (value)
|
||||
locals [GetByteIndex (bitIndex)] |= GetBitValue(bitIndex);
|
||||
else
|
||||
locals [GetByteIndex (bitIndex)] &= (byte) ~GetBitValue(bitIndex);
|
||||
}
|
||||
|
||||
public bool Load (int bitIndex)
|
||||
{
|
||||
var local = locals[GetByteIndex(bitIndex)];
|
||||
byte bitValue = GetBitValue(bitIndex);
|
||||
return (local & bitValue) == bitValue;
|
||||
}
|
||||
|
||||
public byte [] LoadArray ()
|
||||
{
|
||||
return (byte []) locals.Clone ();
|
||||
}
|
||||
|
||||
public int GetLocalCount ()
|
||||
{
|
||||
return locals.Length;
|
||||
}
|
||||
|
||||
public int GetBitCount ()
|
||||
{
|
||||
return bitCount;
|
||||
}
|
||||
|
||||
public byte GetLocal (int i)
|
||||
{
|
||||
return locals [i];
|
||||
}
|
||||
|
||||
public static bool IsBitSet (byte[] bytes, int bitIndex)
|
||||
{
|
||||
int byteIndex = GetByteIndex (bitIndex);
|
||||
byte bitValue = GetBitValue (bitIndex);
|
||||
return (bytes[byteIndex] & bitValue) == bitValue;
|
||||
}
|
||||
|
||||
public static void SetBit (byte[] bytes, int bitIndex)
|
||||
{
|
||||
int byteIndex = GetByteIndex (bitIndex);
|
||||
byte bitValue = GetBitValue (bitIndex);
|
||||
bytes[byteIndex] |= bitValue;
|
||||
}
|
||||
|
||||
static int GetByteIndex (int bitIndex)
|
||||
{
|
||||
return bitIndex >> 3;
|
||||
}
|
||||
|
||||
static byte GetBitValue (int bitIndex)
|
||||
{
|
||||
return (byte)(1 << (bitIndex & 7));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user