64 lines
1.1 KiB
C#
64 lines
1.1 KiB
C#
using System;
|
|
namespace hwo.bitworks
|
|
{
|
|
public class MultipleBitsSource
|
|
{
|
|
protected LogicBase[] sources;
|
|
|
|
public MultipleBitsSource()
|
|
{
|
|
this.sources = null;
|
|
}
|
|
|
|
public MultipleBitsSource(LogicBase[] sources)
|
|
{
|
|
this.sources = sources;
|
|
}
|
|
|
|
public virtual int getBits(){
|
|
return sources.Length;
|
|
}
|
|
|
|
|
|
public virtual bool bitValue(int bit){
|
|
throw new NotImplementedException(String.Format("Class {0} doesn't implement needed method 'bool bitValue(int bit)'",this.GetType().FullName));
|
|
}
|
|
|
|
public LogicBase getLogicalBase(int bit){
|
|
return new BIT(this,bit);
|
|
}
|
|
|
|
public LogicBase[] getLogicalBases(){
|
|
return getLogicalBases(0,getBits());
|
|
}
|
|
public LogicBase[] getLogicalBases(int start,int len){
|
|
LogicBase[] lb = new LogicBase[len];
|
|
|
|
for (int n=0;n<len;n++){
|
|
lb[n] = getLogicalBase(n + start);
|
|
}
|
|
|
|
return lb;
|
|
}
|
|
|
|
public class BIT : LogicBase {
|
|
MultipleBitsSource source;
|
|
int bit;
|
|
|
|
public BIT(MultipleBitsSource source,int bit)
|
|
:base(new LogicBase[0])
|
|
{
|
|
this.source = source;
|
|
this.bit = bit;
|
|
}
|
|
|
|
public override bool value()
|
|
{
|
|
return source.bitValue(this.bit);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|