Created
September 22, 2022 00:45
-
-
Save Josephchinedu/02574bd04b59020251fcd1ca8cf22e24 to your computer and use it in GitHub Desktop.
add binary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
Given two input strings, in a form of binary numbers. Our job is to add them togeth and simply return their sum | |
BINNARY NUMBERS: | |
Binary number are numbers that represent only by zero (0) and one (1) | |
DECIMAL NUMBERS: | |
Decimal numbers are constructed by digit base in columns that are multiple of 10. for example | |
1 9 9 6 | |
1996 = 1 * 1000 + 9 * 100 + 9 * 10 + 6 1 | |
6 * 1 = 6 multiply by 10 to the power of Zero | |
9 * 10 = 10 to the power of 1 * 9 | |
9 * 100 = 10 to the power of 2 * 9 | |
1 * 1000 = 10 to the power of 3 * 1 | |
So, each column in a decimal number represents 10 raise to power of columns position, where position starts at 0 from | |
right side | |
Similarly in a binary number also consist of columns, the columns are multiples of 2 instead of 10 | |
example: 1 0 1 1 | |
1 * 1 = 1 * 2 raise to power of 0 | |
1 * 2 = 1 * 2 raise to power of 1 | |
0 * 4 = 0 * 2 raise to power of 2 | |
1 * 8 = 1 * 2 raise topower of 3 | |
Binary Addition | |
A B A + B SUM CARRY | |
0 0 0 + 0 0 0 | |
0 1 0 + 1 1 0 | |
1 0 1 + 0 1 0 | |
1 1 1 + 1 0 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment