Binaries#

Binary is the base-2 numbering system consisting solely of 0 s and 1 s.

Decimal and Binary Conversion#

Binary to Decimal#

Reverse the order of the binary code and multiply each binary number with its corresponding power of 2, and add the products.

To convert binary 1101 to decimal:

\[ \begin{align}\begin{aligned}1 * (2^0) = 1\\0 * (2^1) = 0\\1 * (2^2) = 4\\1 * (2^3) = 8\end{aligned}\end{align} \]

Binary 1101 in decimal: \(8 + 4 + 0 + 1 = 13\)

Octal to Decimal#

Method A#

Starting from the right, multiply the digits with the corresponding powers of 8 and add the results.

To convert octal number 15 to decimal:

\[ \begin{align}\begin{aligned}1|5 -> 1 * (8^1)|5 * (8^0)\\8|5 -> 8 + 5\\13\end{aligned}\end{align} \]

Octal number 15 in decimal: 13

Method B#

Write the three-digit binary representation of each octal digit side-by-side.

\[ \begin{align}\begin{aligned}0 = 000\\1 = 001\\2 = 010\\3 = 011\\4 = 100\\5 = 101\\6 = 110\\7 = 111\end{aligned}\end{align} \]

To convert octal number 15 to binary:

\[ \begin{align}\begin{aligned}15 -> 1|5\\1|5 -> 001|101\\001101\end{aligned}\end{align} \]

Octal number 15 in binary: 001101

Convert binary to decimal.

Binary 001101 in decimal: 13

Hexadecimal to Decimal#

Method A#

Convert each digit to its corresponding decimal value. Multiply each digits by powers of 16, starting from the rightmost, and sum the products.

\[ \begin{align}\begin{aligned}0 = 0\\1 = 1\\2 = 2\\3 = 3\\4 = 4\\5 = 5\\6 = 6\\7 = 7\\8 = 8\\9 = 9\\10 = A\\11 = B\\12 = C\\13 = D\\14 = E\\15 = F\end{aligned}\end{align} \]

To convert hexadecimal 0xD to decimal:

\[|D -> |13 |13 -> |13 * (16 ^ 0) 13\]

Hexadecimal 0xD in decimal: 13

Method B#

Convert each digit to its corresponding binary value.

\[ \begin{align}\begin{aligned}0 = 0000\\1 = 0001\\2 = 0010\\3 = 0011\\4 = 0100\\5 = 0101\\6 = 0110\\7 = 0111\\8 = 1000\\9 = 1001\\A = 1010\\B = 1011\\C = 1100\\D = 1101\\E = 1110\\F = 1111\end{aligned}\end{align} \]

Convert hexadecimal 0xD to binary:

\[D -> 1101\]

Hexadecimal 0xD in binary: 1101

Convert binary to decimal.

Binary 1101 in decimal: 13

Decimal to Binary#

Return the modulo of the decimal until quotient becomes 0, and reverse the order of remainders. To convert decimal 13 to binary:

\[ \begin{align}\begin{aligned}13 / 2 = 6 r.1\\6 / 2 = 3 r.0\\3 / 2 = 1 r.1\\1 / 2 = 0 . 1\end{aligned}\end{align} \]

Decimal 13 in binary: 1101.

Decimal to Octal#

First, convert decimal to binary.

Starting from the right, group the binary digits into 3. Per group, each digit is represented as 4-2-1—add these up and concatenate the sum of every group. To convert binary 1101 to octal:

\[ \begin{align}\begin{aligned}1101 -> 1|101\\1|(4 + 1) -> 1|5\\15\end{aligned}\end{align} \]

Binary 1101 in octal: 15

Decimal to Hexadecimal#

First, convert decimal to binary.

Group the binary digits into sets of four, starting from the right, and then convert each group into its corresponding hexadecimal digit:

\[ \begin{align}\begin{aligned}0 = 0\\1 = 1\\2 = 2\\3 = 3\\4 = 4\\5 = 5\\6 = 6\\7 = 7\\8 = 8\\9 = 9\\10 = A\\11 = B\\12 = C\\13 = D\\14 = E\\15 = F\end{aligned}\end{align} \]

To convert binary 1101 to hexadecimal:

\[ \begin{align}\begin{aligned}1101 -> |1101\\|(8 + 4 + 0 + 1) -> |13\\13 -> D\end{aligned}\end{align} \]

Binary 1101 in hexadecimal: #D or 0xD

Binary Operations#

Binary Addition

Carry Over

Results

0 + 0

0

0

0 + 1

0

1

1 + 0

0

1

1 + 1

1

0

1 + 1 + 1

1

1

Binary Subtraction

Result

1 - 0

1

1 - 1

0

0 - 0

0

0 - 1

1

Binary Multiplication

Result

0 * 0

0

0 * 1

0

1 * 0

0

1 * 1

1

Binary Division

Result

0 / 1

0

1 / 1

1