CSC373/406: Integers: Unsigned ints [2/9] |

Adding binary and hex numbers

`unsigned`

types

unsigned char x = ...; // 8 bits unsigned int y = x; // 32 bits unsigned int x = ...; unsigned char y = x;

Adding `unsigned`

numbers

unsigned char x = 250; unsigned char y1 = x + 5; unsigned char y2 = x + 6; QUESTION: y1 == 0 QUESTION: y2 == 0

Adding `unsigned`

numbers

Modular arithmetic

unsigned char x = ... unsigned char y = ... unsigned int ix = x; unsigned int iy = y; FACT: ((unsigned char) (x + y)) == ((ix + iy) % 256) FACT: ((unsigned char) (x - y)) == ((ix - iy) % 256) FACT: ((unsigned char) (x * y)) == ((ix * iy) % 256) FACT: ((unsigned char) (x / y)) == ((ix / iy) % 256) /* if y != 0 */

Detecting unsigned overflow

Multiplication/Division by powers of two