ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
sorry mate im a bit of a newbie to java, i cant seem to find the code to just add two binary numbers together, there seems to be some sort of graphical binary program that im not really sure how its working (algerithum wise). Cheers.
In a computer everything is stored as binary internally, so your questions doesn't make much sense to me. Do you mean that you have two strings of ones and zeros that you want to convert to binary and add? If so, I'd just iterate over the strings to construct a numeric variable (easy, if there's a one at position n from the last, add 2^n to your number), then add the numbers and convert the results back to a string of 1s and 0s to dispaly for the user.
btmiller is absolutely correct: you don't have to do anything special to "add in binary". You just ADD two numbers - nothing more!
To *read* a binary number, however, you'll need to convert the character string (e.g. "0110") into the corresponding int (e.g. "6"). Similarly, to *display* as a binary value, you'll need to convert the number into a string of ones and zeros.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.