Unsigned

Description: Can­not rep­re­sent num­ber with neg­a­tive sign, can­not han­dle cal­cu­la­tion with neg­a­tive sign

Range: $0, 2^n-1$

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

To hex: de­v­ide by 4 items per group, then, trans­fer each group's bit to hex

Dec to: keep di­vid­ing by 2, re­sult will be re­main­der in re­versed or­der

Hex to: trans­fer each hex num­ber into 4-bit bi­nary, splic­ing them then

Overflow: re­sult will be $(NUM­BER) mod 2^n$, where as $n$ means the n-bit.

Complement: add 0 till reach limit

Signed/2's Complement

Description: can rep­re­sent sign, can do cal­cu­la­tion with dif­fer­ent sign di­rectly

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

To dec:

  1. if positive, do tranfering like unsigned
  2. 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:

  1. if positive, do tranfering like unsigned, then add 0 to front
  2. 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: de­ter­mine by check­ing if the sign make sense, see if it seat in the range, if so, no over­flow.

the over­flow re­sult de­ter­mined by the sign:

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

To check if over­flow hap­pens in cal­cu­la­tion, re­fer to the im­age be­low:

signed_oveflow
signed_oveflow

remember to pay attention to the direction.