1
Inte
ger
and float numbers
Edited by Carlo U. Nicola, FHNW SG I from the book
of
Randal E. Bryant, David O’Hallaron, “
Introduction to
Computer Systems: A Programmer’s perspective
”,
Prentice Hall, 2002
LLP FS08 2
C puzzles
– Assume machine with 32 bit word size, two’s
complement integers
– For each of the following C expressions, either:
•
Argue that is true for all argument values
•
Give example where not true
x < 0
→
((x*2) < 0)
ux >= 0
x & 7 == 7
→
(x<<30) < 0
ux > -1
x > y
→
-x < -y
x * x >= 0
x > 0 && y > 0
→
x + y > 0
x >= 0
→
-x <= 0
x <= 0
→
-x >= 0
int x = foo();
int y = bar();
unsigned ux = x;
unsigned uy = y;
Initialization