can someone help me with binary addition? i know how it works on paper but when it comes to actually coding it, i cant seem to get it as the addition gives the result of regular addition. for example i know the following
0+0=0
1+0=1
1+1=10 , 1 is carried and 0 is placed.
now when i have 110 + 111 it gives me 221.
what i was thinking of doing is replace the numbers, for example if the last number is 0 and the last number of the second number is 1 then the output is 1. so i would use some if statements, but if doing this then i will have to use some sort of array or something which confuses me and i have no idea how to get past that problem. any suggestions of what i could do?



LinkBack URL
About LinkBacks



but im still having problems, this is only a binary addition, so the user will only enter 0 and 1's which will have to be added. there shouldn't b conversion of the numbers as it will create problems, the add function should add these numbers and output the binary with no conversions made, conversion is not the point. the main point of this is efficiency, and you can achieve that by finding a way to make the program think that 1+ 1 =0 with a carry of 1. maybe i can make use of logical operators and bitwise operators so that i can get the addition to work