53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
|
using System;
|
|||
|
namespace hwo.bitworks
|
|||
|
{
|
|||
|
public class ADDX : MultipleBitsSource
|
|||
|
{
|
|||
|
LogicBase[] srcA,srcB;
|
|||
|
ADD[] add;
|
|||
|
|
|||
|
public ADDX(LogicBase[] sourcesA,LogicBase[] sourcesB)
|
|||
|
{
|
|||
|
int l = sourcesA.Length > sourcesB.Length ? sourcesA.Length : sourcesB.Length;
|
|||
|
|
|||
|
srcA = new LogicBase[l];
|
|||
|
srcB = new LogicBase[l];
|
|||
|
add = new ADD[l];
|
|||
|
|
|||
|
Array.Copy(sourcesA,srcA,sourcesA.Length);
|
|||
|
Array.Copy(sourcesB,srcB,sourcesB.Length);
|
|||
|
|
|||
|
for (int n=sourcesA.Length; n < l; n++){
|
|||
|
srcA[n] = Constants.ZERO;
|
|||
|
}
|
|||
|
for (int n=sourcesB.Length; n < l; n++){
|
|||
|
srcB[n] = Constants.ZERO;
|
|||
|
}
|
|||
|
|
|||
|
LogicBase lb = Constants.ZERO;
|
|||
|
|
|||
|
for (int n=0;n<add.Length;n++){
|
|||
|
add[n] = new ADD(srcA[n],srcB[n],lb);
|
|||
|
lb = add[n].getLogicalBase(1);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override int getBits()
|
|||
|
{
|
|||
|
return add.Length + 1;
|
|||
|
}
|
|||
|
|
|||
|
public override bool bitValue(int bit)
|
|||
|
{
|
|||
|
if (bit > add.Length){
|
|||
|
throw new IndexOutOfRangeException(String.Format("ADDX supplies {0} bits, but bit #{1} requested",add.Length+1,bit));
|
|||
|
} else if (bit == add.Length){
|
|||
|
return add[bit-1].bitValue(1);
|
|||
|
} else {
|
|||
|
return add[bit].bitValue(0);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|