+ 2

How to add two binary number ?

10th Jan 2018, 6:54 AM
Prashant Kumar
Prashant Kumar - avatar
14 Respostas
10th Jan 2018, 7:57 AM
SURYANTO
SURYANTO - avatar
+ 2
https://code.sololearn.com/cqR3Oq02tYbU/?ref=app
10th Jan 2018, 7:36 AM
Elie Douaihy
Elie Douaihy - avatar
+ 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)
10th Jan 2018, 7:21 AM
BlazingMagpie
BlazingMagpie - avatar
+ 1
@Jeremy solve it whatever you want...for me i go with pure programing
10th Jan 2018, 7:40 AM
Elie Douaihy
Elie Douaihy - avatar
+ 1
@Jeremy Some people are interested in learning how binary works and how the built in methods were developed
10th Jan 2018, 7:48 AM
Dan Walker
Dan Walker - avatar
0
Umm, you mean boolean?
10th Jan 2018, 7:00 AM
BlazingMagpie
BlazingMagpie - avatar
0
@Blazing as : 10 + 11 = 101
10th Jan 2018, 7:02 AM
Prashant Kumar
Prashant Kumar - avatar
0
why add them in binary? just add them normally and convert the result to binary
10th Jan 2018, 7:26 AM
Jeremy
Jeremy - avatar
0
@Jeremy can we add 11001011 + 1100001 add normally and then convert result in binary ?
10th Jan 2018, 7:31 AM
Prashant Kumar
Prashant Kumar - avatar
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
10th Jan 2018, 7:33 AM
Jeremy
Jeremy - avatar
10th Jan 2018, 7:35 AM
Jeremy
Jeremy - avatar
0
no need to reinvent the wheel @Elie Douaihy
10th Jan 2018, 7:37 AM
Jeremy
Jeremy - avatar
0
aka wasting cpu time and memory. Those built in methods exist for a reason ;)
10th Jan 2018, 7:42 AM
Jeremy
Jeremy - avatar