Results 21 to 32 of 32
Thread: binary addition and Substraction
 10152011, 03:40 PM #21
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,354
 Blog Entries
 7
 Rep Power
 20
 10152011, 04:17 PM #22Member
 Join Date
 Oct 2011
 Posts
 1
 Rep Power
 0
Re: binary addition and Substraction
i would recommend you to brush up your basics at following site Home
 10152011, 04:23 PM #23Member
 Join Date
 Oct 2011
 Posts
 20
 Rep Power
 0
Re: binary addition and Substraction
hi again, that worked, but now the only problem is that in this part of the code i think
jTextField1.getText();
jTextField2.getText();
vem=vai;
result_final="";
while (jTextField1.getText().isEmpty());
{
bin1=Integer.parseInt(jTextField1.getText());
bin2=Integer.parseInt(jTextField2.getText());
if ((vem==0)&(alg1==0)&(alg2==0))
{
vai=0;
somabin=0;
}
THE PROGRAM JUST TEST THE FIRST IF, AND RETURN ALWAYS THE VALUE I PUT IN THE FIRST SOMABIN
if (((vem==0)&(alg1==1)&(alg2==0))  ((vem==0)&(alg1==0)&(alg2==1)))
{
vai=0;
somabin=1;
}
the original code in pascal is here, check it please, to see if i forgot something :) http://www.pcforum.com.br/cgi/yabb/Y...num=1111089082Last edited by m1ke4fun; 10152011 at 04:26 PM.
 10152011, 04:39 PM #24
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,354
 Blog Entries
 7
 Rep Power
 20
Re: binary addition and Substraction
You are reading the values of those textfields in bin1 and bin2, but you are testing variable alg1 and alg2 ... there is something fishy going on there. btw, your program structure is faulty too, i.e. you don't check text fields for being empty like that. If you stole that code from a Pascal solution, remember that Java is not Pascal.
kind regards,
Joscenosillicaphobia: the fear for an empty beer glass
 10152011, 05:10 PM #25Member
 Join Date
 Oct 2011
 Posts
 20
 Rep Power
 0
Re: binary addition and Substraction
hey again, i made a new code, with fixes, and, i can make the
0 + 0 → 0
0 + 1 → 1
1 + 0 → 1
1 + 1 → 0, carry 1
do i create a new variable to the mecanism? or use the alg1(and until it got numbers, do repetition??
 10152011, 05:22 PM #26
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,354
 Blog Entries
 7
 Rep Power
 20
Re: binary addition and Substraction
I gave you a complete solution in a previous reply above (it didn't have the preposterous logic you copied either) but you refused it; you are on your own now.
kind regards,
Joscenosillicaphobia: the fear for an empty beer glass
 10152011, 06:31 PM #27Member
 Join Date
 Oct 2011
 Posts
 20
 Rep Power
 0
Re: binary addition and Substraction
all i need is a variable that got the lenght of textfield1, and test it, if the lenght of textfield >=1 , it will do the if repetition, , but i am lost on that

Re: binary addition and Substraction
Please show your latest code that uses Jos's solution.
 10152011, 06:49 PM #29Member
 Join Date
 Oct 2011
 Posts
 20
 Rep Power
 0
Re: binary addition and Substraction
its a java application
got 2 textfields, 1 botton, 1 label
in this code, only do the add with one digit, if i put 2 always return 0, for example 1+1=10 ,1+0=1 , 0+0=0 ;but if i put 10+10=0 ;
i am noob, so i use if's
Java Code:private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String resposta, result_final,result; int n1, n2, i,alg1, alg2, somabin, vai, vem, erro, bin1,bin2; result_final=""; result=""; i= (jTextField1.getText().length()); alg1=Integer.valueOf(jTextField1.getText()); alg2=Integer.valueOf(jTextField2.getText()); if ((vem==0)&(alg1==0)&(alg2==0)) { vai=0; somabin=0; } if (((vem==0)&(alg1==1)&(alg2==0))  ((vem==0)&(alg1==0)&(alg2==1))) { vai=0; somabin=1; } if ((vem==0)&(alg1==1)&(alg2==1)) { vai=1; somabin=0; } if ((vem==1)&(alg1==0)&(alg2==0)) { vai=0; somabin=1; } if (((vem==1) & (alg1==1) & (alg2==0))  ((vem==1) & (alg1==0) & (alg2==1))) { vai=1; somabin=0; } if ((vem==1)&(alg1==1)&(alg2==1)) { vai=1; somabin=1; } result=String.valueOf(somabin); vem=vai; result_final=result+result_final; if (vem==1) { result_final=1+result_final; } jLabel1.setText(result_final); }
Last edited by m1ke4fun; 10152011 at 07:04 PM. Reason: quote tags changed to code tags

Re: binary addition and Substraction
I've changed your [quote] and [/quote] tags into [code] and [/code] tags to help your code retain its formatting and be more readable, but this isn't helping because you're not posting formatted code with proper indentation. Please edit the post above and change your unformatted code to properly formatted code so that we can read it.
 10152011, 07:05 PM #31Member
 Join Date
 Oct 2011
 Posts
 20
 Rep Power
 0
Re: binary addition and Substraction
edited, i think :)
 10162011, 10:04 PM #32Member
 Join Date
 Oct 2011
 Posts
 20
 Rep Power
 0
Re: binary addition and Substraction
Java Code:private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String resposta, result_final,result; int n1, n2, i,alg1, alg2, somabin, vai, vem, erro, bin1,bin2; result_final=""; result=""; i= (jTextField1.getText().length()); alg1=Integer.valueOf(jTextField1.getText()); alg2=Integer.valueOf(jTextField2.getText()); if ((vem==0)&(alg1==0)&(alg2==0)) { vai=0; somabin=0; } if (((vem==0)&(alg1==1)&(alg2==0))  ((vem==0)&(alg1==0)&(alg2==1))) { vai=0; somabin=1; } if ((vem==0)&(alg1==1)&(alg2==1)) { vai=1; somabin=0; } /**if ((vem==1)&(alg1==0)&(alg2==0)) { vai=0; somabin=1; } if (((vem==1) & (alg1==1) & (alg2==0))  ((vem==1) & (alg1==0) & (alg2==1))) { vai=1; somabin=0; } if ((vem==1)&(alg1==1)&(alg2==1)) { vai=1; somabin=1; } */ result=String.valueOf(somabin); vem=vai; result_final=result+result_final; if (vem==1) { result_final=1+result_final; } jLabel1.setText(result_final); }
Similar Threads

addition
By rithish in forum New To JavaReplies: 4Last Post: 10042011, 08:15 AM 
java binary addition
By rockdude in forum New To JavaReplies: 1Last Post: 03182009, 03:01 PM 
Need help on my project on JAVA BINARY ADDITION
By arneltroy in forum New To JavaReplies: 3Last Post: 01312009, 03:33 AM 
Addition of Two time
By jithan in forum New To JavaReplies: 5Last Post: 12292008, 11:09 AM 
Binary Addition
By Deo Favente in forum Advanced JavaReplies: 11Last Post: 04242008, 05:34 AM
Bookmarks