Last active
October 14, 2019 17:35
-
-
Save zion830/aca2597da243b63fcc59742a194e3785 to your computer and use it in GitHub Desktop.
전가산기, 반가산기 만들어보기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Adder { | |
public boolean[] byteadder(boolean[] byteA, boolean[] byteB) { | |
boolean[] answer = new boolean[9]; | |
boolean carry = false; | |
for (int i = 0; i < answer.length - 1; i++) { | |
boolean[] value = fulladder(byteA[i], byteB[i], carry); | |
answer[i] = value[1]; | |
carry = value[0]; | |
} | |
answer[8] = carry; | |
return answer; | |
} | |
public boolean[] fulladder(boolean bitA, boolean bitB, boolean c) { | |
boolean sum = ((bitA != bitB) != c); | |
boolean carry = (bitA && bitB) || (bitA && c) || (bitB && c); | |
return new boolean[]{carry, sum}; | |
} | |
public boolean[] halfadder(boolean bitA, boolean bitB) { | |
boolean sum = (bitA != bitB); | |
boolean carry = (bitA && bitB); | |
return new boolean[]{carry, sum}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment