Ask your own question, for FREE!
Mathematics 7 Online
OpenStudy (anonymous):

**Java** I'm trying to make a program that adds and subtracts binary numbers. The way I was assigned to do it is take two numbers, then turn their sum and difference into binary code while only showing them in binary. Like.. The steps that I have? The user inputs two numbers. The code prints the two numbers in binary. Then the sum and difference is calculated of the original numbers, and printed in binary. What I have so far: import java.util.Scanner; public class Kiana{ public static void main (String[]args){ Scanner input = new Scanner(System.in); Along those lines.

OpenStudy (bibby):

there are different ways of adding binary numbers including 2s complement and 1s complement. you can look up some code to convert integers to binary, I wrote something here if you're lazy (but it's in cpp and not java) https://gist.github.com/bibsoft/6796795

OpenStudy (amistre64):

(1203)_10 1203/2 = 601 + R1 601/2 = 300 + R1 300/2 = 150 + R0 150/2 = 75 + R0 75/2 = 37 + R1 37/2 = 18 + R1 18/2 = 9 + R0 9/2 = 4 + R1 4/2 = 2 + R0 2/2 = 1 + R0 1/2 = 0 + R1 read bottom to top; this is (10010110011)_2

OpenStudy (amistre64):

if we dont want to divide, then k mod 2 creates the list as well

OpenStudy (amistre64):

once we have placement determined, then its just picking rules for adding the binary vectors, might want to keep a carry box to add in as needed

OpenStudy (amistre64):

just a thought ....

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!