Binary is used to represent data in a way that computers can read since it is in base 2
Binary can be used in logic gates with 0 representing off and 1 representing on
Denary (base 10): 0
Binary (base 2): 0
Hexadecimal (base 16): 0
When dividing by 2 and only using integers a right shift is done which removes the least significant bit
This works fine for positive, integer numbers.
To make negative numbers work you would need a set bit length
Two's complement works by interpreting binary numbers in the same way that you would for positive numbers, but giving the most significant digit a negative weight
The table below uses this method in 4 bits.
| Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | -1 | -2 | -3 | -4 | -5 | -6 | -7 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1111 | 1110 | 1101 | 1100 | 1011 | 1010 | 1001 |
Binary can represent fractional numbers by spliting the denary number at the decimal place
2.6875 becomes 2 and 0.6875
When representing decimals such as 0.6875 in binary, negative powers of 2 are used
2-1 = 0.5 , smaller than remainder so new remainder becomes 0.1875
2-2 = 0.25 , larger than remainder
2-3 = 0.125 , smaller than remainder so new remainder becomes 0.0625
2-4 = 0.0625 , equal to the remainder so now the remainder is 0
so 2.687510 becomes 10.10112
Denary (base 10): 0
Binary (base 2): 0
Hexadecimal (base 16): 0
Now outputs decimals aswell