## Unsigned

**Description**: Cannot represent number with negative sign, cannot handle calculation with negative sign

**Range**: $0, 2^n-1$

**To dec**: $bit * 2^n + ....$

**To hex**: devide by 4 items per group, then, transfer each group's bit to hex

**Dec to**: keep dividing by 2, result will be remainder in reversed order

**Hex to**: transfer each hex number into 4-bit binary, splicing them then

**Overflow**: result will be $(NUMBER) mod 2^n$, where as $n$ means the n-bit.

**Complement**: add 0 till reach limit

## Signed/2's Complement

**Description**: can represent sign, can do calculation with different sign directly

**Range**: $-2^{n-1}, 2^{n-1}-1$

**To dec**:

- if positive, do tranfering like unsigned
- if negative, do transfering like unsigned but treat the first bit as $-2^n * bit$ instead of $2^n * bit$. The second way is to remove first bit, flip all bits, add one, then do like unsigned. remember to add the negative sign to the final result

**Dec to**:

- if positive, do tranfering like unsigned, then add 0 to front
- if negative, remove first bit, flip all bits, add one, then do like unsigned. remember to add the negative sign to the final result

**Overflow**: determine by checking if the sign make sense, see if it seat in the range, if so, no overflow.

the overflow result determined by the sign:

- if positive, the result will be $NUMBER - 2^n$
- if negative, the result will be $NUMBER + 2^n$

To check if overflow happens in calculation, refer to the image below:

*remember to pay attention to the direction.*