Binary-hex-decimal
Give the requested representations:
Little Endian/Big Endian
A 4 byte signed integer is stored at locations 0x8000 - 0x8003
Stored Address Byte 0x8000: 0x00 0x8001: 0x01 0x8002: 0x02 0x8003: 0x00
If the machine is little endian, what is the integer value (in decimal)? Ans: (2 * 164 + 1 * 162) = 131328
If the machine is big endian, what is the integer value (in decimal)? Ans: (1 * 164 + 2 * 162) = 66048
C pointers
If the integer array x begins at address 0x8000 and
int x[3] = {10, 20, 30}; int *p; int *q; p = &x[0]; q = &x[1];
give the values of the following expressions:
C Bit Operations (in binary)
Give the value of following expressions in binary if the values of a and b in binary are:
a = 1100 b = 1010
! the 'bang' operator
Is there a value of the int variable x such that
x == !!x
Ans: Yes. For example, x = 0.
C bit operations (in hex)
Give the value of following expressions in hex if the values of a and b in hex are:
a = 0xC b = 0xA
Left Shift (in binary)
For the 1 byte (8 bit) signed integer
char x = 0x6A; // 011010102
Give the value in hex and binary of the following shift operations:
Arithmetic Right Shift (in binary and hex)
For the 1 byte (8 bit) signed integer, assume right shift is arithmetic
char x = 0x6A; // 011010102 char y = 0x8A; // 100010102
Give the value in hex and binary of the following shift operations:
Logical Right Shift (in binary and hex)
For the 1 byte (8 bit) unsigned integer, assume right shift is logical
char x = 0x6A; // 011010102 char y = 0x8A; // 100010102
Give the value in hex and binary of the following shift operations:
Write the function f below that returns an integer like y except the low order 2 bytes are 0.
Example: If y = 0x12AB86C3, the function f should return the value 0x12AB0000.
int f(int x) { ... }
return y & 0xFFFF0000; or
return y & (~0 << 16);
Truncation, Sign Extension
For some initial values of x at line 1, the value of x after line 3 not the same as the initial value.
There are many possible answers. One answer is 0x00008000. Give two other possible answers.
1 int x = ?; // Ans: 0x00008000
2 short s = x; // assigns 0x8000 to s (truncation)
3 x = s; // assigns 0xffff8000 to x (sign extension)
Ans: one answer: 0x0000C000, another answer: 0xffff7000
IEEE floating point
A 32 bit IEEE float value has hex representation:
0x40B00000
Give the decimal representation of this float number.
Ans: 5.5
IEEE floating point types
Give an 32 bit example (in hex) of each of the following:
Signed/Unsigned comparision
The sizeof(T) function returns the size in bytes of a value of type T. For example, sizeof(char) is 1, sizeof(short) is 2, sizeof(int) is 4, sizeof(double) is 8. Since the size of any type is never negative, the return type of sizeof is unsigned int.
What is the output of the following program?
int main() { int x; x = -1; while( x < sizeof(int) ) { x++; printf("x = %d\n", x); } printf("Done\n"); return 0; }
Ans: Done