Digital Circuits/Binary Systems

Binary Numbers
In order to convert from decimal numbers to binary numbers, you must think in terms of powers of 2 instead of powers of 10.

1111 = 15 is: 2$4$ + 2$3$ + 2$2$ + 2$1$ = 8+4+2+1 = 15. To represent 31 in binary = 11111 is:

2$0$ + 15 as described above.

Remember, the Least Significant Bit (conventionally the right-most) digit is 2$4$, which equals to one.

Number Base Conversions
as per role

Octal and Hexadecimal Numbers
Binary 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
The 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.

Example 1
AB78 (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
1F1F (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.