42 lines
574 B
C#
42 lines
574 B
C#
|
using System;
|
|||
|
namespace hwo.bitworks
|
|||
|
{
|
|||
|
public class BitBuffer : MultipleBitsSource
|
|||
|
{
|
|||
|
bool[] bits;
|
|||
|
|
|||
|
public BitBuffer(int len)
|
|||
|
{
|
|||
|
this.bits = new bool[len];
|
|||
|
}
|
|||
|
|
|||
|
public override int getBits()
|
|||
|
{
|
|||
|
return bits.Length;
|
|||
|
}
|
|||
|
|
|||
|
public void zero(){
|
|||
|
for (int n=0;n<bits.Length;n++)
|
|||
|
bits[n] = false;
|
|||
|
}
|
|||
|
|
|||
|
public void set(Int32 i){
|
|||
|
zero();
|
|||
|
|
|||
|
int w = 32 < getBits() ? 32 : getBits();
|
|||
|
|
|||
|
for (int n=0;n<w;n++){
|
|||
|
bits[n] = (i & (1<<n)) == 0 ? false : true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override bool bitValue(int bit)
|
|||
|
{
|
|||
|
return this.bits[ bit ];
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|