public DynamicAdder(int bits) { fullAdders = new FullAdder[bits]; var inputPinSeriesA = new InputPin[bits]; var inputPinSeriesB = new InputPin[bits]; var outputPinSeriesSum = new OutputPin[bits]; FullAdder previousFullAdder = null; for (var i = 0; i < bits; i++) { var fullAdder = new FullAdder(); if (previousFullAdder != null) { previousFullAdder.CarryOver.ConnectTo(fullAdder.CarryIn); } fullAdders[i] = fullAdder; inputPinSeriesA[i] = fullAdder.InputA; inputPinSeriesB[i] = fullAdder.InputB; outputPinSeriesSum[i] = fullAdder.Sum; previousFullAdder = fullAdder; } Overflow = previousFullAdder.CarryOver; InputA = new InputPinSeries(inputPinSeriesA); InputB = new InputPinSeries(inputPinSeriesB); Sum = new OutputPinSeries(outputPinSeriesSum); }
public static void Set(this InputPinSeries inputPinSeries, int value) { //Thanks SO //https://stackoverflow.com/questions/6758196/convert-int-to-a-bit-array-in-net var bitArray = new BitArray(BitConverter.GetBytes(value)); for (var i = 0; i < inputPinSeries.Length; i++) { inputPinSeries[i] = bitArray[i]; } }
public void PinSeriesConvertsToIntCorrectly() { //Given const int expectedValue = 0b00110110; var pinSeries = new InputPinSeries( GetInputPin(false), GetInputPin(true), GetInputPin(true), GetInputPin(false), GetInputPin(true), GetInputPin(true), GetInputPin(false), GetInputPin(false) ); //When var actualValue = pinSeries.Read(); //Then actualValue.Should().Be(expectedValue); }
public Comparer8Bit() { InputA = new InputPinSeries(Comparer1.InputA, Comparer2.InputA, Comparer3.InputA, Comparer4.InputA, Comparer5.InputA, Comparer6.InputA, Comparer7.InputA, Comparer8.InputA); InputB = new InputPinSeries(Comparer1.InputB, Comparer2.InputB, Comparer3.InputB, Comparer4.InputB, Comparer5.InputB, Comparer6.InputB, Comparer7.InputB, Comparer8.InputB); Comparer8.IsOn.State = true; ChainComparer(Comparer8, Comparer7); ChainComparer(Comparer7, Comparer6); ChainComparer(Comparer6, Comparer5); ChainComparer(Comparer5, Comparer4); ChainComparer(Comparer4, Comparer3); ChainComparer(Comparer3, Comparer2); ChainComparer(Comparer2, Comparer1); }
public void IntConvertsToPinSeriesCorrectly() { //Given const int intValue = 0b00110110; var pinSeries = new InputPinSeries(GetInputPin(), GetInputPin(), GetInputPin(), GetInputPin(), GetInputPin(), GetInputPin(), GetInputPin(), GetInputPin()); //When pinSeries.Set(intValue); //Then pinSeries[0].Should().BeFalse(); pinSeries[1].Should().BeTrue(); pinSeries[2].Should().BeTrue(); pinSeries[3].Should().BeFalse(); pinSeries[4].Should().BeTrue(); pinSeries[5].Should().BeTrue(); pinSeries[6].Should().BeFalse(); pinSeries[7].Should().BeFalse(); }
public Subtracter8Bit() { InputA = new InputPinSeries(fullSubtracter1.InputA, fullSubtracter2.InputA, fullSubtracter3.InputA, fullSubtracter4.InputA, fullSubtracter5.InputA, fullSubtracter6.InputA, fullSubtracter7.InputA, fullSubtracter8.InputA); InputB = new InputPinSeries(fullSubtracter1.InputB, fullSubtracter2.InputB, fullSubtracter3.InputB, fullSubtracter4.InputB, fullSubtracter5.InputB, fullSubtracter6.InputB, fullSubtracter7.InputB, fullSubtracter8.InputB); Sub = new OutputPinSeries(fullSubtracter1.Sub, fullSubtracter2.Sub, fullSubtracter3.Sub, fullSubtracter4.Sub, fullSubtracter5.Sub, fullSubtracter6.Sub, fullSubtracter7.Sub, fullSubtracter8.Sub); fullSubtracter1.CarryOver.ConnectTo(fullSubtracter2.CarryIn); fullSubtracter2.CarryOver.ConnectTo(fullSubtracter3.CarryIn); fullSubtracter3.CarryOver.ConnectTo(fullSubtracter4.CarryIn); fullSubtracter4.CarryOver.ConnectTo(fullSubtracter5.CarryIn); fullSubtracter5.CarryOver.ConnectTo(fullSubtracter6.CarryIn); fullSubtracter6.CarryOver.ConnectTo(fullSubtracter7.CarryIn); fullSubtracter7.CarryOver.ConnectTo(fullSubtracter8.CarryIn); Overflow = fullSubtracter8.CarryOver; }