Binary numeral system: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Pat Palmer
mNo edit summary
imported>Anthony Argyriou
(expand)
Line 1: Line 1:
The '''binary number system''', also referred to as base-2, or [[radix]]-2, represents [[number]]s using only the [[digit]]s 0 and 1. This is in contrast with the more familiar [[decimal number system]] (a.k.a. base-10, [[radix]]-10) which uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. In the decimal system, each digit position represents a [[power of]] ten. The number <math>10</math> represents the value consisting of one set of tens (<math>10^1</math>), and no sets of ones (<math>10^0</math>). Equivalently in the binary system each digit position represents a power of two. The same number, <math>10</math> represents the value consisting of one set of twos (<math>2^1</math>) and no sets of ones (<math>2^0</math>) which is represented by the number 2 in the decimal system. When the numbering system used for a number is in question, one can write the radix as a subscript to the number as done in the following table.
The '''binary number system''', also referred to as base-2, or [[radix]]-2, represents [[number]]s using only the [[digit]]s 0 and 1. This is in contrast with the more familiar [[decimal number system]] (a.k.a. base-10, [[radix]]-10) which uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. In the binary system each digit position represents a power of two. The same number, <math>10</math> represents the value consisting of one set of twos (<math>2^1</math>) and no sets of ones (<math>2^0</math>)which is represented by the number 2 in the decimal system. This is equivalent to the decimal system, where each digit position represents a [[power of]] ten. The number <math>10</math> represents the value consisting of one set of tens (<math>10^1</math>), and no sets of ones (<math>10^0</math>).   When the numbering system used for a number is in question, one can write the radix as a subscript to the number as done in the following table.


<table cellpadding="3" cellspacing="0" border="1">
<table cellpadding="3" cellspacing="0" border="1">
<tr>
<th>Binary</th>
<td><math>100_2 = (1 \times 2^2)+(0 \times 2^1)+(0 \times 2^0)= 4_{10} + 0 + 0 = 4_{10}</math></td>
</tr>
<tr>
<tr>
<th>Decimal</th>
<th>Decimal</th>
<td><math>100_{10} = (1 \times 10^2) + (0 \times 10^1) + (0 \times 10^0)</math></td>
<td><math>100_{10} = (1 \times 10^2) + (0 \times 10^1) + (0 \times 10^0)</math></td>
</tr>
</tr>
<tr>
<th>Binary</th>
<td><math>100_2 = (1 \times 2^2)+(0 \times 2^1)+(0 \times 2^0)= 4_{10} + 0 + 0 = 4_{10}</math></td>
</tr>
</table>
</table>


Because the number of digits in the binary representation of a value can grow quickly, binary values are often represented in the [[hexadecimal number system]] (base-16), which uses the digits 0 through 9, followed by the letters A through F to represent the values ten, eleven, twelve, thirteen, fourteen, and fifteen.
The binary system is used is most electronic computers, as the values of 0 and 1 can be easily represented by a low and a high voltage in a circuit.
 
==Binary arithmetic==
Arithmetic with binary numbers is similar to arithmetic with decimal numbers, except that the addition and multiplication tables are much simpler:
<table cellpadding="10" border="0">
<tr><td>
<table cellpadding="3" cellspacing="1" border="1">
<tr align="right"><td><math>+</math></td><td><math>0</math></td><td><math>1</math></td></tr>
<tr align="right"><td><math>0</math></td><td><math>0</math></td><td><math>1</math></td></tr>
<tr align="right"><td><math>1</math></td><td><math>1</math></td><td><math>10</math></td></tr>
</table>
</td><td>
<table cellpadding="3" cellspacing="1" border="1">
<tr align="right"><td><math>\times</math></td><td><math>0</math></td><td><math>1</math></td></tr>
<tr align="right"><td><math>0</math></td><td><math>0</math></td><td><math>0</math></td></tr>
<tr align="right"><td><math>1</math></td><td><math>0</math></td><td><math>1</math></td></tr>
</table>
</td></tr></table>
 
Division and subtraction are performed in the same way as for decimal numbers, but using the corresponding rules for binary addition and multiplication. Non-integer quantities can be represented as binary digits to the right of the binary point. For example, <math>3/16 = 0.1875_{10} = 0.0011_2 = (0 \times 2^0)+(0 \times 2^{-1})+(0 \times 2^{-2})+(1 \times 2^{-3})+(1 \times 2^{-4})</math>
 
Repeating binary expansions also occur, for any fraction where the denominator is not a power of 2. For example, <math>1/5 = 0.001100110011_2</math> (with 0011 repeating).
 
Irrational numbers can also be expressed, and will have irregular distributions of digits. For example, <math>\pi = 11.001001000011111..._2</math>
 
==Other representations==
Because the number of digits in the binary representation of a value can grow quickly, when human readability is desired, binary values are often represented in the [[octal number system]] (base 8) or the [[hexadecimal number system]] (base 16). Octal uses the digits 0 through 7; hexadecimal uses the digits 0 through 9, followed by the letters A through F to represent the values ten, eleven, twelve, thirteen, fourteen, and fifteen.


<table cellpadding="3" cellspacing="0" border="1">
<table cellpadding="3" cellspacing="0" border="1">
Line 18: Line 44:
<th>Decimal</th>
<th>Decimal</th>
<th>Binary</th>
<th>Binary</th>
<th>Octal</th>
<th>Hexadecimal</th>
<th>Hexadecimal</th>
</tr>
</tr>


<tr>
<tr>
<td valign="top" align="right">0</td>
<td valign="top" align="right">0</td>
<td valign="top" align="right">0</td>
<td valign="top" align="right">0</td>
<td valign="top" align="right">0</td>
Line 27: Line 55:
</tr>
</tr>
<tr>
<tr>
<td valign="top" align="right">1</td>
<td valign="top" align="right">1</td>
<td valign="top" align="right">1</td>
<td valign="top" align="right">1</td>
<td valign="top" align="right">1</td>
Line 34: Line 63:
<td valign="top" align="right">2</td>
<td valign="top" align="right">2</td>
<td valign="top" align="right">10</td>
<td valign="top" align="right">10</td>
<td valign="top" align="right">2</td>
<td valign="top" align="right">2</td>
<td valign="top" align="right">2</td>
</tr>
</tr>
Line 39: Line 69:
<td valign="top" align="right">3</td>
<td valign="top" align="right">3</td>
<td valign="top" align="right">11</td>
<td valign="top" align="right">11</td>
<td valign="top" align="right">3</td>
<td valign="top" align="right">3</td>
<td valign="top" align="right">3</td>
</tr>
</tr>
Line 44: Line 75:
<td valign="top" align="right">4</td>
<td valign="top" align="right">4</td>
<td valign="top" align="right">100</td>
<td valign="top" align="right">100</td>
<td valign="top" align="right">4</td>
<td valign="top" align="right">4</td>
<td valign="top" align="right">4</td>
</tr>
</tr>
Line 49: Line 81:
<td valign="top" align="right">5</td>
<td valign="top" align="right">5</td>
<td valign="top" align="right">101</td>
<td valign="top" align="right">101</td>
<td valign="top" align="right">5</td>
<td valign="top" align="right">5</td>
<td valign="top" align="right">5</td>
</tr>
</tr>
Line 54: Line 87:
<td valign="top" align="right">6</td>
<td valign="top" align="right">6</td>
<td valign="top" align="right">110</td>
<td valign="top" align="right">110</td>
<td valign="top" align="right">6</td>
<td valign="top" align="right">6</td>
<td valign="top" align="right">6</td>
</tr>
</tr>
Line 59: Line 93:
<td valign="top" align="right">7</td>
<td valign="top" align="right">7</td>
<td valign="top" align="right">111</td>
<td valign="top" align="right">111</td>
<td valign="top" align="right">7</td>
<td valign="top" align="right">7</td>
<td valign="top" align="right">7</td>
</tr>
</tr>
Line 64: Line 99:
<td valign="top" align="right">8</td>
<td valign="top" align="right">8</td>
<td valign="top" align="right">1000</td>
<td valign="top" align="right">1000</td>
<td valign="top" align="right">10</td>
<td valign="top" align="right">8</td>
<td valign="top" align="right">8</td>
</tr>
</tr>
Line 69: Line 105:
<td valign="top" align="right">9</td>
<td valign="top" align="right">9</td>
<td valign="top" align="right">1001</td>
<td valign="top" align="right">1001</td>
<td valign="top" align="right">11</td>
<td valign="top" align="right">9</td>
<td valign="top" align="right">9</td>
</tr>
</tr>
Line 74: Line 111:
<td valign="top" align="right">10</td>
<td valign="top" align="right">10</td>
<td valign="top" align="right">1010</td>
<td valign="top" align="right">1010</td>
<td valign="top" align="right">12</td>
<td valign="top" align="right">A</td>
<td valign="top" align="right">A</td>
</tr>
</tr>
Line 79: Line 117:
<td valign="top" align="right">11</td>
<td valign="top" align="right">11</td>
<td valign="top" align="right">1011</td>
<td valign="top" align="right">1011</td>
<td valign="top" align="right">13</td>
<td valign="top" align="right">B</td>
<td valign="top" align="right">B</td>
</tr>
</tr>
Line 84: Line 123:
<td valign="top" align="right">12</td>
<td valign="top" align="right">12</td>
<td valign="top" align="right">1100</td>
<td valign="top" align="right">1100</td>
<td valign="top" align="right">14</td>
<td valign="top" align="right">C</td>
<td valign="top" align="right">C</td>
</tr>
</tr>
Line 89: Line 129:
<td valign="top" align="right">13</td>
<td valign="top" align="right">13</td>
<td valign="top" align="right">1101</td>
<td valign="top" align="right">1101</td>
<td valign="top" align="right">15</td>
<td valign="top" align="right">D</td>
<td valign="top" align="right">D</td>
</tr>
</tr>
Line 94: Line 135:
<td valign="top" align="right">14</td>
<td valign="top" align="right">14</td>
<td valign="top" align="right">1110</td>
<td valign="top" align="right">1110</td>
<td valign="top" align="right">16</td>
<td valign="top" align="right">E</td>
<td valign="top" align="right">E</td>
</tr>
</tr>
Line 99: Line 141:
<td valign="top" align="right">15</td>
<td valign="top" align="right">15</td>
<td valign="top" align="right">1111</td>
<td valign="top" align="right">1111</td>
<td valign="top" align="right">17</td>
<td valign="top" align="right">F</td>
<td valign="top" align="right">F</td>
</tr>
</tr>
Line 104: Line 147:
<td valign="top" align="right">16</td>
<td valign="top" align="right">16</td>
<td valign="top" align="right">10000</td>
<td valign="top" align="right">10000</td>
<td valign="top" align="right">20</td>
<td valign="top" align="right">10</td>
<td valign="top" align="right">10</td>
</tr>
<tr>
<td valign="top" align="right">17</td>
<td valign="top" align="right">10001</td>
<td valign="top" align="right">21</td>
<td valign="top" align="right">11</td>
</tr>
<tr>
<td valign="top" align="right">20</td>
<td valign="top" align="right">10100</td>
<td valign="top" align="right">24</td>
<td valign="top" align="right">14</td>
</tr>
<tr>
<td valign="top" align="right">25</td>
<td valign="top" align="right">11001</td>
<td valign="top" align="right">31</td>
<td valign="top" align="right">19</td>
</tr>
<tr>
<td valign="top" align="right">32</td>
<td valign="top" align="right">100000</td>
<td valign="top" align="right">40</td>
<td valign="top" align="right">20</td>
</tr>
<tr>
<td valign="top" align="right">40</td>
<td valign="top" align="right">101000</td>
<td valign="top" align="right">50</td>
<td valign="top" align="right">28</td>
</tr>
<tr>
<td valign="top" align="right">49</td>
<td valign="top" align="right">110001</td>
<td valign="top" align="right">61</td>
<td valign="top" align="right">31</td>
</tr>
<tr>
<td valign="top" align="right">63</td>
<td valign="top" align="right">111111</td>
<td valign="top" align="right">77</td>
<td valign="top" align="right">3F</td>
</tr>
<tr>
<td valign="top" align="right">99</td>
<td valign="top" align="right">1100011</td>
<td valign="top" align="right">143</td>
<td valign="top" align="right">63</td>
</tr>
</tr>
</table>
</table>

Revision as of 11:09, 28 April 2007

The binary number system, also referred to as base-2, or radix-2, represents numbers using only the digits 0 and 1. This is in contrast with the more familiar decimal number system (a.k.a. base-10, radix-10) which uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. In the binary system each digit position represents a power of two. The same number, Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 10} represents the value consisting of one set of twos (Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 2^1} ) and no sets of ones (Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 2^0} )which is represented by the number 2 in the decimal system. This is equivalent to the decimal system, where each digit position represents a power of ten. The number Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 10} represents the value consisting of one set of tens (Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 10^1} ), and no sets of ones (Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 10^0} ). When the numbering system used for a number is in question, one can write the radix as a subscript to the number as done in the following table.

Binary Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 100_2 = (1 \times 2^2)+(0 \times 2^1)+(0 \times 2^0)= 4_{10} + 0 + 0 = 4_{10}}
Decimal Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 100_{10} = (1 \times 10^2) + (0 \times 10^1) + (0 \times 10^0)}

The binary system is used is most electronic computers, as the values of 0 and 1 can be easily represented by a low and a high voltage in a circuit.

Binary arithmetic

Arithmetic with binary numbers is similar to arithmetic with decimal numbers, except that the addition and multiplication tables are much simpler:

Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle +} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 0} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 1}
Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 0} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 0} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 1}
Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 1} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 1} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 10}
Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \times} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 0} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 1}
Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 0} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 0} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 0}
Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 1} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 0} Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 1}

Division and subtraction are performed in the same way as for decimal numbers, but using the corresponding rules for binary addition and multiplication. Non-integer quantities can be represented as binary digits to the right of the binary point. For example, Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 3/16 = 0.1875_{10} = 0.0011_2 = (0 \times 2^0)+(0 \times 2^{-1})+(0 \times 2^{-2})+(1 \times 2^{-3})+(1 \times 2^{-4})}

Repeating binary expansions also occur, for any fraction where the denominator is not a power of 2. For example, Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle 1/5 = 0.001100110011_2} (with 0011 repeating).

Irrational numbers can also be expressed, and will have irregular distributions of digits. For example, Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \pi = 11.001001000011111..._2}

Other representations

Because the number of digits in the binary representation of a value can grow quickly, when human readability is desired, binary values are often represented in the octal number system (base 8) or the hexadecimal number system (base 16). Octal uses the digits 0 through 7; hexadecimal uses the digits 0 through 9, followed by the letters A through F to represent the values ten, eleven, twelve, thirteen, fourteen, and fifteen.

Decimal Binary Octal Hexadecimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 10000 20 10
17 10001 21 11
20 10100 24 14
25 11001 31 19
32 100000 40 20
40 101000 50 28
49 110001 61 31
63 111111 77 3F
99 1100011 143 63