36 lines
822 B
C#
36 lines
822 B
C#
using System;
|
|
namespace hwo.bitworks
|
|
{
|
|
public class ShiftLeft : MultipleBitsSource
|
|
{
|
|
int n;
|
|
|
|
public ShiftLeft(LogicBase[] sources,int n)
|
|
:base(sources)
|
|
{
|
|
this.n = n;
|
|
}
|
|
|
|
public override bool bitValue(int bit)
|
|
{
|
|
if (bit < this.n){
|
|
return false;
|
|
} else if (bit < getBits()){
|
|
return sources[bit - this.n].value();
|
|
}
|
|
throw new IndexOutOfRangeException(String.Format("ShiftLeft supplies {0} bits, but bit #{1} requested",getBits(),bit));
|
|
}
|
|
|
|
public override identity.BitIdentity getBitIdentity(int bit)
|
|
{
|
|
if (bit < this.n){
|
|
return Constants.ZERO.identity();
|
|
} else if (bit < getBits()){
|
|
return sources[bit - this.n].identity();
|
|
}
|
|
throw new IndexOutOfRangeException(String.Format("ShiftLeft supplies {0} bits, but bit #{1} requested",getBits(),bit));
|
|
}
|
|
|
|
}
|
|
}
|