Digital Circuits/Binary Systems
Binary Numbers
editDecimal | Binary | Octal
(base 8) |
Hexadecimal
(base 16) |
---|---|---|---|
00 | 0000 | 00 | 0 |
01 | 0001 | 01 | 1 |
02 | 0010 | 02 | 2 |
03 | 0011 | 03 | 3 |
04 | 0100 | 04 | 4 |
05 | 0101 | 05 | 5 |
06 | 0110 | 06 | 6 |
07 | 0111 | 07 | 7 |
08 | 1000 | 10 | 8 |
09 | 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 |
In order to convert from decimal numbers to binary numbers, you must think in terms of powers of 2 instead of powers of 10.
Power Representation | 24 | 23 | 22 | 21 | 20 |
---|---|---|---|---|---|
Weight | 16 | 8 | 4 | 2 | 1 |
1111 = 15 is:
Power Representation | 24 | 23 | 22 | 21 | 20 |
---|---|---|---|---|---|
Weight | 16 | 8 | 4 | 2 | 1 |
Decimal Value "15" | 0 | 1 | 1 | 1 | 1 |
23 + 22 + 21 + 20 = 8+4+2+1 = 15.
To represent 31 in binary = 11111 is:
24 + 15 as described above.
Remember, the Least Significant Bit (conventionally the right-most) digit is 20, which equals to one.
Number Base Conversions
editas per role
Octal and Hexadecimal Numbers
editBinary is the intrinsic number system of digital circuits, but long strings of 1s and 0s are not easy for humans to read and write. Therefore, number systems with easy conversion to and from binary were developed, including octal and hexadecimal.
The octal number system is base 8, in contrast to our native number system (decimal) which is base 10. In base 8, only the numbers 0 through 7 are used. Each octal digit can be represented by three binary bits, as shown in the conversion table above (under Binary Numbers).
Conversion between octal and binary is straightforward. To convert from octal to binary, convert each octal digit to its three-bit equivalent, and vice versa.
Similarly, the hexadecimal number system, base 16, facilitates easy conversion to and from binary. Each hexadecimal digit represents exactly four binary bits, as shown in the table above.
Note that in hexadecimal, the letters A through F are used to represent the decimal equivalent of 10 through 15, respectively.
Long strings of bits can be represented in a much more compact fashion using octal and hexadecimal. Of the two, hexadecimal is more commonly used. As each hexadecimal digit represents four bits, hexadecimal is well-suited to represent values likely to be found in modern systems (16, 32 or 64 bits). Hexadecimal values are often prefixed with the expression "0x" - for instance, 0xFF is the hexadecimal equivalent of 255.
Complements
editThe one's complement is computed by taking the given number, written in binary, and then "flipping" each bit, such that every 0 in the original is now represented as 1 in the one's complement, and every 1 in the original is represented as 0. The logical AND of a binary number and its one’s complement is all 0’s. The logical OR of a binary number and its one’s complement is all 1’s.
The two's complement is formed by taking the one’s complement of a binary value and then adding 1 to it. The two's complement serves the purpose of representing signed integers. The negative of a number is represented as the two's complement of the original. Subtraction can be performed by adding the negative (two’s complement) of a value to another. The minimum integer that can be represented by N bits is -2N-1, while the maximum number is 2N-1-1.
Examples
editExample 1
editAB78 (hexadecimal) = 1010 1011 0111 1000 (binary) The one's complement of 0xAB78 is 0101 0100 1000 0111. The two's complement of 0xAB78 is 0101 0100 1000 1000.
Example 2
edit1F1F (hexadecimal)=0001 1111 0001 1111 (binary) The one's complement of 0x1F1F is 1110 0000 1110 0000. The two's complement of 0x1F1F is 1110 0000 1110 0001.