DEV Community

Cover image for Binary numbers mathematical operations
Harutyun Martirosyan
Harutyun Martirosyan

Posted on

Binary numbers mathematical operations

Adding

  1010
+ 1101
-------
 10111

Explanation:
0 + 1 = 1
1 + 0 = 1
0 + 1 = 1
1 + 1 = 0 (carry 1)
1 + 1 + 1 = 1 (carry 1)

Enter fullscreen mode Exit fullscreen mode
  1001
+ 0110
-------
  1111

Explanation:
1 + 0 = 1
0 + 1 = 1
0 + 1 = 1
1 + 0 = 1
Enter fullscreen mode Exit fullscreen mode
  101  
+  11  
-------
 1000  

Explanation:
1 + 1 = 0 (carry 1)
0 + 1 + 1(carried over) = 0 (carry 1)
1 + 0 + 1(carried over) = 10(with carried 1)

Enter fullscreen mode Exit fullscreen mode

Subtracting

  1010
-  010
-------
  1000

Explanation:
0 - 0 = 0
1 - 1 = 0
0 - 0 = 0
1 - 0 = 1
Enter fullscreen mode Exit fullscreen mode
  1100
- 0011
-------
  1001

Explanation:
0(becomes 2) - 1 = 1 (borrow 1)
0(becomes 1) - 1 = 0
1 - 0 = 0
1 - 0 = 1
Enter fullscreen mode Exit fullscreen mode
  10000
- 00101
-------
  10111

Explanation:
0(becomes 2) - 1 = 1 (borrow 1)
0(becomes 1) - 0 = 1
0(becomes 1) - 1 = 0 
0(becomes 1)- 0 = 1
1(becomes 0) - 0 = 0
Enter fullscreen mode Exit fullscreen mode

Multiplying

    101
  x  11
--------
    101   
+  101   
--------
  1111

   Explanation:
First column:   Second column:   Adding columns:
1 * 1 = 1       1 * 1 = 1        101
0 * 1 = 0       0 * 1 = 0     + 101
1 * 1 = 1       1 * 1 = 1       ----
                                1111 
Enter fullscreen mode Exit fullscreen mode
     1011
  x   101
 --------
     1011   
+   0000    
+  1011   
 --------
   110111
   Explanation:
First column:   Second column:  Third column:  Adding columns:
1 * 1 = 1       1 * 0 = 0       1 * 1 = 1            1011
1 * 1 = 1       1 * 0 = 0       1 * 1 = 1       +   0000
0 * 1 = 0       0 * 0 = 0       0 * 1 = 0       +  1011
1 * 1 = 1       1 * 0 = 0       1 * 1 = 1       ---------
                                                   110111
Enter fullscreen mode Exit fullscreen mode
    111
  x 111
--------
    111 
+  111   
+ 111   
--------
 110001

    Explanation:
First column:   Second column:  Third column:  Adding columns:
1 * 1 = 1       1 * 1 = 1       1 * 1 = 1           111
1 * 1 = 1       1 * 1 = 1       1 * 1 = 1       +  111
1 * 1 = 1       1 * 1 = 1       1 * 1 = 1       + 111
                                                --------
                                                 110001
Enter fullscreen mode Exit fullscreen mode

Divison

     11
   -----
10 | 110
    -10
   -----
      10
    - 10
   -----
      00

Enter fullscreen mode Exit fullscreen mode
      101
    ------
11 | 1111
    -11
    ------
       1
    ------
       11
      -11
    ------
       00

Enter fullscreen mode Exit fullscreen mode
      10
    ------
10 | 100
    -10
    ------
      00

Enter fullscreen mode Exit fullscreen mode

Top comments (0)