I
I
Ivan the Terrible2015-10-11 14:41:37
Java
Ivan the Terrible, 2015-10-11 14:41:37

How to add binary numbers in JAVA?

How to implement addition of two binary numbers in Java?
For example, there is a number int - 11111010 and you need to add the number to it according to the rules of addition of binary numbers:
00000001. How to do it ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DR_Demons, 2015-10-11
@warriorkg

Integer.toBinaryString(Integer.parseInt("11111010", 2) + Integer.parseInt("00000001", 2))

M
Maxim Moseychuk, 2015-10-11
@fshp

If your number is already int, then take it and add it with the addition operator ("+" for those who skipped math).
Otherwise, translate your (most likely) string representation into int, long or BigInteger, and work with it already.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question