53 lines
863 B
C#
53 lines
863 B
C#
using System;
|
|
namespace hwo.bitworks
|
|
{
|
|
public class BitBuffer : MultipleBitsSource
|
|
{
|
|
bool[] bits;
|
|
string name;
|
|
|
|
public BitBuffer(int len)
|
|
{
|
|
this.bits = new bool[len];
|
|
this.name = SourceName;
|
|
}
|
|
public BitBuffer(int len,string name)
|
|
{
|
|
this.bits = new bool[len];
|
|
this.name = name;
|
|
}
|
|
|
|
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 ];
|
|
}
|
|
|
|
public override identity.BitIdentity getBitIdentity(int bit)
|
|
{
|
|
return new identity.BitIdentity(String.Format("{0}({1})",this.name,bit));
|
|
}
|
|
|
|
|
|
}
|
|
}
|