Binary

From Compsci1

(Difference between revisions)
(Rules of Binary Addition)
 
(6 intermediate revisions not shown)
Line 10: Line 10:
1 + 1 = 0, and carry 1 to the next more significant bit  
1 + 1 = 0, and carry 1 to the next more significant bit  
 +
For example,
For example,
-
00011010 + 00001100 = 00100110                 1  1   carries  
+
00011010 + 00001100 = 00100110  
 +
 +
      1  1                     carries  
 +
 
 +
0  0  0  1  1  0  1  0    =    26<sub>(base 10)</sub>
-
  0  0  0  1  1  0 1 0    =    26(base 10)  
+
0  0  0  1  1  0  0    =    12<sub>(base 10) </sub>
-
+ 0  0  0  0  1  1  0  0
+
+
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-
     =    12(base 10)
+
      
-
 
+
0  0  1  0  0  1  1  0    =    38<sub>(base 10) </sub>
-
  0  0  1  0  0  1  1  0    =    38(base 10)  
+
   
   
    
    
-
00010011 + 00111110 = 01010001           1  1  1  1  1   carries
+
00010011 + 00111110 = 01010001   
-
  0 0  0 1 0  0 1  1   =    19(base 10)
+
    1 1 1  1  1               carries
-
+ 0  0  1 1 1 0
+
0  0  0 0 0 1    =    19<sub>(base 10) </sub>
-
--------------------------------------------------------------------------------
+
0  0  1  1  1  1  1  0    =    62<sub>(base 10) </sub>
-
    =    62(base 10)
+
+
-
 
+
-
  0  1  0  1  0  0  0  1    =    81(base 10)
+
-
 
+
-
 
+
-
Note:  The rules of binary addition (without carries) are the same as the truths of the XOR gate.
+
 +
----------------------------------------------------------------------
 +
 
 +
  0  1  0  1  0  0  0  1    =    81<sub>(base 10)</sub>
==Rules of Binary Subtraction==
==Rules of Binary Subtraction==
0 - 0 = 0  
0 - 0 = 0  
 +
0 - 1 = 1, and borrow 1 from the next more significant bit  
0 - 1 = 1, and borrow 1 from the next more significant bit  
 +
1 - 0 = 1  
1 - 0 = 1  
 +
1 - 1 = 0  
1 - 1 = 0  
 +
For example,
For example,
-
00100101 - 00010001 = 00010100                 0  borrows
+
00100101 - 00010001 = 00010100  
-
  0  0  1 10  0  1  0  1    =    37(base 10)
+
-
- 0  0  0  1  0  0  0  1
+
-
--------------------------------------------------------------------------------
+
-
    =    17(base 10)
+
-
  0  0  0  1  0  1  0  0    =    20(base 10)
+
-
+
-
 
+
-
00110011 - 00010110 = 00011101              0 10  1  borrows
+
-
  0  0  1  1  0 10  1  1    =    51(base 10)
+
-
- 0  0  0  1  0  1  1  0
+
-
--------------------------------------------------------------------------------
+
-
    =    22(base 10)
+
-
  0  0  0  1  1  1  0  1    =    29(base 10)
+
 +
      0                        borrows
 +
0  0  <strike>1</strike> <sup>1</sup>0  0  1  0  1    =    37<sub>(base 10) </sub>
-
Rules of Binary Multiplication
+
0 0 0 1 0 0 0 1   =   17<sub>(base 10)</sub>
-
0 x 0 = 0  
+
-
0 x 1 = 0  
+
-
1 x 0 = 0  
+
-
1 x 1 = 1, and no carry or borrow bits
+
-
For example,
+
-
00101001 × 00000110 = 11110110          0  0  1  0  1  0  0  1    =    41(base 10)
+
-
-
× 0  0  0  0  0  1  1  0
+
 
-
--------------------------------------------------------------------------------
+
-------------------------------------------------------------
-
    =    6(base 10)
+
 
-
0 0  0  0  0  0  0 
+
  0  0  0  1  0  1  0  0    =    20<sub>(base 10)</sub>
-
0  0  1  0  1  0 0  1     
+
-
0  0  1  0  1  0  0  1     
+
-
--------------------------------------------------------------------------------
+
-
 
+
-
0  0  1  1  1  1  0  1  1 0    =    246(base 10)  
+
   
   
    
    
-
00010111 × 00000011 = 01000101          0  0  0  1  0  1  1  1    =    23(base 10)
+
00110011 - 00010110 = 00011101  
-
× 0  0  0  0  0  0  1  1
+
      0 <sup>1</sup>0  1                   borrows
-
--------------------------------------------------------------------------------
+
-
    =   3(base 10)
+
-
  1 1  1  1  1        carries
+
-
0 0  0  1 0  1 1  1 
+
-
0  0  0  1  0  1  1  1 
+
-
--------------------------------------------------------------------------------
+
-
 
+
-
0  0  1  0  0  0  1  0  1    =    69(base 10)
+
-
Note: The rules of binary multiplication are the same as the truths of the AND gate.
+
  0  0  <strike>1  1  0 </strike><sup>1</sup>0  1  1    =    51<sub>(base 10)</sub>
 +
 +
0  0  0  1  0  1  1  0    =    22<sub>(base 10)</sub>
-
Another Method:  Binary multiplication is the same as repeated binary addition; add the multicand to itself the multiplier number of times.
+
-
-
 
+
-
For example,
+
-
00001000 × 00000011 = 00011000                    1  carries
 
-
  0  0  0  0  1  0  0  0    =    8(base 10)
 
-
  0  0  0  0  1  0  0  0    =    8(base 10)
 
-
+ 0  0  0  0  1  0  0  0
 
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-
    =    8(base 10)
+
   
-
  0  0  0  1  1  0 0   =    24(base 10)  
+
0  0  0  1  1  1 1   =    29<sub>(base 10)</sub>
-
Binary Division
 
-
Binary division is the repeated process of subtraction, just as in decimal division.
 
-
For example,
 
-
00101010 ÷ 00000110 = 00000111                        1  1  1    =    7(base 10)
 
-
--------------------------------------------------------------------------------
 
-
 
-
1  1  0  )  0  0  1  10  1  0  1  0    =    42(base 10)
 
-
        -    1  1  0        =    6(base 10)
 
-
 
 
-
--------------------------------------------------------------------------------
 
-
 
 
-
        1          borrows
 
-
      1  0  10  1   
 
-
      -    1  1  0   
 
-
 
 
-
--------------------------------------------------------------------------------
 
-
 
 
-
            1  1  0 
 
-
        -    1  1  0 
 
-
 
 
-
--------------------------------------------------------------------------------
 
-
 
-
              0 
 
-
 
-
 
 
-
10000111 ÷ 00000101 = 00011011                    1  1  0  1  1    =    27(base 10)
 
-
--------------------------------------------------------------------------------
+
Notes
-
+
-
1  0  1  )  1  0  0  10  0  1  1  1    =    135(base 10)
+
-
    -    1  0  1            =    5(base 10)
+
-
--------------------------------------------------------------------------------
+
Binary Number System
-
 
+
-
    1  1  10       
+
-
  -    1  0  1       
+
-
 
+
-
--------------------------------------------------------------------------------
+
-
 
+
-
        1  1     
+
-
      -      0     
+
-
 
+
-
--------------------------------------------------------------------------------
+
-
 
+
-
        1  1  1   
+
-
      -    1  0  1   
+
-
 
+
-
--------------------------------------------------------------------------------
+
-
 
+
-
          1  0  1 
+
-
        -    1  0  1 
+
-
 
+
-
--------------------------------------------------------------------------------
+
-
+
-
              0 
+
 +
System Digits:  0 and 1
-
 
-
Notes
 
-
Binary Number System
 
-
System Digits:  0 and 1
 
Bit (short for binary digit):  A single binary digit  
Bit (short for binary digit):  A single binary digit  
 +
LSB (least significant bit):  The rightmost bit  
LSB (least significant bit):  The rightmost bit  
 +
MSB (most significant bit):  The leftmost bit  
MSB (most significant bit):  The leftmost bit  
 +
Upper Byte (or nybble):  The right-hand byte (or nybble) of a pair  
Upper Byte (or nybble):  The right-hand byte (or nybble) of a pair  
 +
Lower Byte (or nybble):  The left-hand byte (or nybble) of a pair  
Lower Byte (or nybble):  The left-hand byte (or nybble) of a pair  
    
    
Binary Equivalents  
Binary Equivalents  
 +
1 Nybble (or nibble)  =  4 bits  
1 Nybble (or nibble)  =  4 bits  
-
1 Byte  =  2 nybbles  =  8 bits  
+
 
 +
1 Byte  =  2 nybbles  =  8 bits
 +
1 Kilobyte (KB)  =  1024 bytes  
1 Kilobyte (KB)  =  1024 bytes  
 +
1 Megabyte (MB)  =  1024 kilobytes  =  1,048,576 bytes  
1 Megabyte (MB)  =  1024 kilobytes  =  1,048,576 bytes  
 +
1 Gigabyte (GB)  =  1024 megabytes  =  1,073,741,824 bytes
1 Gigabyte (GB)  =  1024 megabytes  =  1,073,741,824 bytes

Current revision as of 20:31, 1 October 2006

a good resource on Binary

Rules of Binary Addition

0 + 0 = 0

0 + 1 = 1

1 + 0 = 1

1 + 1 = 0, and carry 1 to the next more significant bit

For example,

00011010 + 00001100 = 00100110

      1  1                     carries 
0  0  0  1  1  0  1  0    =    26(base 10) 
0  0  0  0  1  1  0  0    =    12(base 10) 

+



0  0  1  0  0  1  1  0    =    38(base 10) 


00010011 + 00111110 = 01010001

   1  1  1  1  1               carries 
0  0  0  1  0  0  1  1    =    19(base 10) 
0  0  1  1  1  1  1  0    =    62(base 10) 

+



 0  1  0  1  0  0  0  1    =    81(base 10)

Rules of Binary Subtraction

0 - 0 = 0

0 - 1 = 1, and borrow 1 from the next more significant bit

1 - 0 = 1

1 - 1 = 0

For example,

00100101 - 00010001 = 00010100

      0                        borrows 
0  0  1 10  0  1  0  1    =    37(base 10) 
0  0  0  1  0  0  0  1    =    17(base 10) 

-


0  0  0  1  0  1  0  0    =    20(base 10) 

 

00110011 - 00010110 = 00011101

      0 10  1                   borrows 
0  0  1  1  0 10  1  1    =    51(base 10)

0  0  0  1  0  1  1  0    =    22(base 10) 

-


0  0  0  1  1  1  0  1    =    29(base 10)




Notes

Binary Number System

System Digits: 0 and 1

Bit (short for binary digit): A single binary digit

LSB (least significant bit): The rightmost bit

MSB (most significant bit): The leftmost bit

Upper Byte (or nybble): The right-hand byte (or nybble) of a pair

Lower Byte (or nybble): The left-hand byte (or nybble) of a pair

Binary Equivalents

1 Nybble (or nibble) = 4 bits

1 Byte = 2 nybbles = 8 bits

1 Kilobyte (KB) = 1024 bytes

1 Megabyte (MB) = 1024 kilobytes = 1,048,576 bytes

1 Gigabyte (GB) = 1024 megabytes = 1,073,741,824 bytes

Personal tools
Handy Pages