Data representation
Values and bases
A particular value can have multiple representations. For example, $15_{10}$ in is $1111_2$ (binary) and $F_{16}$ (hexadecimal). The general formula to calculate a value given a representation is
$$ value = \sum^{n-1}_{i=0} symbol_i \times base^i $$ where $n$ is the number of positions and $i=0$ is the LSB.
The octal 243 has value $3 \times 8^0 + 4 \times 8^1 + 2 \times 8^2 = 3 + 32 + 128 = 163_{10}$.
The binary 0110 1101 has value $2^0 + 2^2 + 2^3 + 2^5 + 2^6 = 1 + 4 + 8 + 32 + 64 = 109_{10}$.
The hexadecimal 5AF3 has value $3 \times 16^0 + 15 \times 16^1 + 10 \times 16^2 + 5 \times 16^3 = 3 + 240 + 2560 + 20480 = 23283_{10}$.
Signed magnitude representation
The most significant bit declares whether the number is positive or negative, then the rest of the bits are standard binary. For example, $-15$ in 8-bit signed magnitude would be $10001111$. 1111 is 15 as usual and the MSB being 1 represents negative.
Two's complement
Two's complement is the most common signed integer representation. The MSB is worth it's negative value and the remaining bits have standard value. For example, $-3$ is represented $1101$, because the MSB represents $-8$ and $101$ represents 5 and $-8+5=-3$.
To find the two's complement of a negative number take the binary representation of the positive number, invert the bits and add 1. So for $-3$ the binary representation of positive 3 is 0011. Inverting the bits gives 1100 and adding one gives 1101. Note that when adding 1 any overflow should be ignored.
Numbers in two's complement can be added as usual.
Fixed point representation
Decimal numbers can be expressed using fixed point representation, where a fixed number of bits is used for the whole and fractional part of a number. For example, $7.625$ with 8 bits, 4 for either part would be $0111.1010$. This representation is very inefficient for very large or very small numbers.
Floating point representation
Floating point representation is analogous to scientific notation, such as $5.6 \times 10^3$. It consists of a mantissa and exponent. For IEEE floating point there are 3 levels of precision - single, double and quad using 32, 64 and 128 bits respectively. Single precision uses 1 bit for the sign, 8 for the exponent and 23 for the mantissa.