CS230 Midterm 1 || Graded A+ Already.
As a four-armed animal, Duncan the Dog prefers to represent numbers using a base 4 number
system. If Duncan gives you the base 4 number 1110, what is the equivalent decimal value?
correct answers 64 + 16 + 4 = 84
Associate the variable types with their storage sizes in a x86-32bit machine.
char
short
int
double correct answers char: 1
short: 2
int: 4
double: 8
You are doing a right shift using signed 8-bit binary numbers.
Convert -25 to a signed 8-bit binary number in two's complement.
Then do >> 4.
What is the decimal value of this number? correct answers Convert -25 to signed 8-biy binary
number in twos complement: 25 = 11001
-25 (in 2s complement) = 11100111
>>4 = 11111110
Convert to decimal:
11111101 -> 00000010
= 2 *-1 = -2
The answer: -2
We wish to examine two values 𝑎 and 𝑏 in memory and generate a new one which satisfies the
following: if both 𝑎 and 𝑏 have the same value in a particular bit position, then that position in
our new value should be a 1, otherwise it is 0. For instance, if 𝑎 = 0101 and 𝑏 = 0111 then the
new value will be 1101. Which of the following generates our desired value? correct answers
~(a^b)
What is the minimal number of bits required to represent (unsigned) hexadecimal 48F? correct
answers 11
What's the result (in binary) of adding the two 8-bit binary numbers 00111110 and 01000010?
Please indicate if there's an overflow or underflow happen after the computation. signed?
unsigned? correct answers signed: 10000000 (overflow: sum of two positive numbers causes
negative number)
unsigned: 10000000
In the context of IEEE Standard for Single Precision Floating Point representation, the value
given is '0 10000000 111000000000000000000', what is its decimal equivalent, i.e., 0.001?
correct answers 3.75
, Given a 8 digit binary number 11010001 in Two's Complement, please convert it to a decimal
number. correct answers -47
You are doing a right shift using signed 8-bit binary numbers.
Convert -26 to a signed 8-bit binary number in two's complement.
Then do >> 4.
What is the decimal value of this number? correct answers -2
What is the output of the following code?
unsigned int z = 23;
int count = 0;
for(z = 9; z >= 0; z--){
count++;
}
printf("%d", count); correct answers No output. It is an infinite loop.
unsigned int
The data type of a variable is important in programming languages like C. In addition to telling
the compiler how much space to allocate for a variable, they also give information on how to
interpret a sequence of bits. Consider you use an unsigned short (size: 2 bytes) pointer to store
the following bits:
00001000 00001110
Then you dereference the pointer to obtain a value, and print the referenced in base 10. what
value would be printed?
hint: the decimal number of 00001000 is 8 and the decimal number of 00001110 is 14. correct
answers 100000001110 = 2062
As a four-armed animal, Duncan the Dog prefers to represent numbers using a base 4 number
system. If Duncan gives you the base 4 number 2232, what is the equivalent decimal value?
correct answers 174
Please evaluate the following boolean operations of 10000101 & 00000110. The answer should
be a binary number. correct answers 00000100
Assume we have a machine that uses 1 byte for a short int and 2 bytes for an int. What's the
binary value of z after running the following code.
short int x = -109; // binary sequence is 10010011
int y = x;
unsigned int z = y; correct answers 1111111110010011
Let 𝑘>𝑚>�>�> 1 and 𝑎≥�≥ 1 be an unbounded integer. What does the following equate to?
correct answers
As a four-armed animal, Duncan the Dog prefers to represent numbers using a base 4 number
system. If Duncan gives you the base 4 number 1110, what is the equivalent decimal value?
correct answers 64 + 16 + 4 = 84
Associate the variable types with their storage sizes in a x86-32bit machine.
char
short
int
double correct answers char: 1
short: 2
int: 4
double: 8
You are doing a right shift using signed 8-bit binary numbers.
Convert -25 to a signed 8-bit binary number in two's complement.
Then do >> 4.
What is the decimal value of this number? correct answers Convert -25 to signed 8-biy binary
number in twos complement: 25 = 11001
-25 (in 2s complement) = 11100111
>>4 = 11111110
Convert to decimal:
11111101 -> 00000010
= 2 *-1 = -2
The answer: -2
We wish to examine two values 𝑎 and 𝑏 in memory and generate a new one which satisfies the
following: if both 𝑎 and 𝑏 have the same value in a particular bit position, then that position in
our new value should be a 1, otherwise it is 0. For instance, if 𝑎 = 0101 and 𝑏 = 0111 then the
new value will be 1101. Which of the following generates our desired value? correct answers
~(a^b)
What is the minimal number of bits required to represent (unsigned) hexadecimal 48F? correct
answers 11
What's the result (in binary) of adding the two 8-bit binary numbers 00111110 and 01000010?
Please indicate if there's an overflow or underflow happen after the computation. signed?
unsigned? correct answers signed: 10000000 (overflow: sum of two positive numbers causes
negative number)
unsigned: 10000000
In the context of IEEE Standard for Single Precision Floating Point representation, the value
given is '0 10000000 111000000000000000000', what is its decimal equivalent, i.e., 0.001?
correct answers 3.75
, Given a 8 digit binary number 11010001 in Two's Complement, please convert it to a decimal
number. correct answers -47
You are doing a right shift using signed 8-bit binary numbers.
Convert -26 to a signed 8-bit binary number in two's complement.
Then do >> 4.
What is the decimal value of this number? correct answers -2
What is the output of the following code?
unsigned int z = 23;
int count = 0;
for(z = 9; z >= 0; z--){
count++;
}
printf("%d", count); correct answers No output. It is an infinite loop.
unsigned int
The data type of a variable is important in programming languages like C. In addition to telling
the compiler how much space to allocate for a variable, they also give information on how to
interpret a sequence of bits. Consider you use an unsigned short (size: 2 bytes) pointer to store
the following bits:
00001000 00001110
Then you dereference the pointer to obtain a value, and print the referenced in base 10. what
value would be printed?
hint: the decimal number of 00001000 is 8 and the decimal number of 00001110 is 14. correct
answers 100000001110 = 2062
As a four-armed animal, Duncan the Dog prefers to represent numbers using a base 4 number
system. If Duncan gives you the base 4 number 2232, what is the equivalent decimal value?
correct answers 174
Please evaluate the following boolean operations of 10000101 & 00000110. The answer should
be a binary number. correct answers 00000100
Assume we have a machine that uses 1 byte for a short int and 2 bytes for an int. What's the
binary value of z after running the following code.
short int x = -109; // binary sequence is 10010011
int y = x;
unsigned int z = y; correct answers 1111111110010011
Let 𝑘>𝑚>�>�> 1 and 𝑎≥�≥ 1 be an unbounded integer. What does the following equate to?
correct answers