# Integer Representations Exercises

## p1 (integer sizes)

How many bytes do the following types take up on a common 64-bit computer such as the Myth machines?

`unsigned long`

`short`

`signed char`

What C code could you write to determine the above?

## p2 (integer ranges)

What is the range of integral values representable by each of the following types?

`unsigned long`

`short`

`signed char`

## p3 (signedness)

Suppose Andrew writes `0b1111_1111`

on the board. He assures you that this is a
8-bit integer. What value does it represent? (Hint: trick question)

## p4 (two's complement)

- You are given
`0b1110_1011`

, a`signed char`

. Determine its decimal value. - You write the following code:

`signed char x = -13;`

What is the underlying bit pattern of the `signed char`

?

## p5 (overflow)

Alpha, Bravo, and Charlie are trying to write a C expression for the floored
average of two `unsigned int`

's. (That is, the average rounded down to the
nearest `unsigned int`

.) What do you think about their proposals?

- Alpha:
`(x+y)/2`

- Bravo:
`x/2 + y/2`

- Charlie:
`x + (y-x)/2`