+ 2
How to add two binary number ?
14 Respostas
+ 2
+ 2
https://code.sololearn.com/cqR3Oq02tYbU/?ref=app
+ 1
Oh, you mean actual binary numbers.
It's not particularly difficult, you just need to remember that it's only in base 2 and you can add them like numbers in any other base. For example, with base 4, when you reach 4, instead of writing 4 you carry it over to another digit, just like in decimal system instead of having a symbol for 10, you carry it over:
(base 4) 3 + 1 = 10
(base 4) 33 + 3 = 30 + (3 + 3) = 30 + 12 = 102(18 in decimal)
just like
(base 10) 9 + 1 = 10
(base 10) 99 + 3 = 90 + (9 + 3) = 90 + 12 = 102
So in base 2, or binary, you do the same:
(base 2) 1 + 1 = 10
(base 2) 11 + 1 = 10 + (1 + 1) = 10 + 10 = 100(4 in decimal)
+ 1
@Jeremy solve it whatever you want...for me i go with pure programing
+ 1
@Jeremy
Some people are interested in learning how binary works and how the built in methods were developed
0
Umm, you mean boolean?
0
@Blazing
as :
10 + 11 = 101
0
why add them in binary? just add them normally and convert the result to binary
0
@Jeremy
can we add 11001011 + 1100001 add normally and then convert result in binary ?
0
you need to write it in javas binary form eg: int bin = 0b11001011 after adding it to something you can do Integer.toBinaryString(bin) and get the binary as string
0
i made u an example
https://code.sololearn.com/c1Web6mgxvcb/?ref=app
0
no need to reinvent the wheel @Elie Douaihy
0
aka wasting cpu time and memory. Those built in methods exist for a reason ;)