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