Uploaded by zjletcher

Exam COMP 305 Prep/Notes

advertisement
Exam 1 Prep
What is the 8-bit binary
representation of the decimal
value 19?
What is the 8-bit binary
representation of the decimal
value 19?
__0__ __0__ __0__ __1__ __0__ __0__ __1__ __1__
What is the 8-bit binary 2’s
complement representation of
the decimal value -29?
What is the 8-bit binary 2’s
complement representation of
the decimal value -29?
__1__ __1__ __1__ __0__ __0__ __0__ __1__ __1__
What is the 4-bit binary
representation for the decimal
value 6?
What is the 4-bit binary
representation for the decimal
value 6?
0110
What is the hexadecimal
representation of the octal value
123?
What is the hexadecimal
representation of the octal value
123?
0123 == 001 010 011 == 0 0101 0011 == 0x53
What is the octal representation
for the hexadecimal value 0x34?
What is the octal representation for the hexadecimal value 0x34?
Binary representation:
0011 0100
Regroup:
00 110 100
Octal:
064
What is the 8-bit two’s
complement representation of
-3?
What is the 8-bit two’s complement
representation of -3?
3 => 0000 0011
Complement:
Add 1:
1111 1100
1111 1101
What is the decimal value of the
unsigned 8-bit integer 0x81?
What is the decimal value of the unsigned 8-bit integer 0x81?
8 * 16 + 1 == 128 + 1 == 129
What is the decimal value of the signed 8-bit
integer 0x81?
What is the decimal value of the signed 8-bit
integer 0x81?
Binary: 1000 0001 high order bit is 1 so value is negative
Complement:
0111 1110
Add 1:
0111 1111
Decimal with sign:
-127
What does the standard function
isspace do?
What does the standard function
isspace do?
Returns true if the character argument is one of the white space characters.
Given a one byte variable V containing a
3-bit field F in bit positions 1 to 3 (bit
position 0 is the least significant bit, write
the expression that extracts the value of F
from V.
Given a one byte variable V containing a
3-bit field F in bit positions 1 to 3 (bit
position 0 is the least significant bit, write
the expression that extracts the value of F
from V.
F = (V >> 1) & 7
Given a 32-bit word W containing a 6-bit field
in bit positions 12 to 17 (bit position 0 is the
least significant bit), write the assignment
statements to store the int value X into that
field without altering the other bits in W.
Given a 32-bit word W containing a 6-bit field
in bit positions 12 to 17 (bit position 0 is the
least significant bit), write the assignment
statements to store the int value X into that
field without altering the other bits in W.
W &= 0xFFFC0FFF; // clear the field within W
X &= 0x3F; // make sure X is valid
W |= (X << 12);
Alternative:
W = (W & 0xFFFC0FFF) |
( (X & 0x3F) << 12);
What is the value of the expression:
((1 << 3) – 1) & 6
What is the value of the expression:
((1 << 3) – 1) & 6
(8 – 1) & 6
7&6
6
0111 & 0110
What is the value of the expression:
1 << 2 + 3 << 4
What is the value of the expression:
1 << 2 + 3 << 4
(1 << (2 + 3)) << 4
(1 << 5) << 4
32 << 4
512
This is an operator precedence problem
Given the function declaration:
void reverse(char * dest, char * src);
This function copies the characters from src to
dest in reverse. So, a call like reverse(d, “cat”)
would result in the string pointed to by d having
the value “tac”. Write this function.
void reverse(char * dest, char * src)
{
int len = strlen(src);
dest[len] = 0;
for (int i=0; i<len; ++i)
{
dest[len-i-1] = src[i];
}
}
Write a C function that takes an unsigned
integer parameter and returns ¾ of that
value without using any multiplications or
divisions. For example, if the parameter has
a value of 16 the result should be 12.
unsigned int threeFourths(unsigned int x)
{
return (x >> 2) + (x >> 1);
}
x/4
x/2
Given an 8 bit value where 4 of the bits are to the right of the
binary point, what does the binary value 00000001 represent?
Given an 8 bit value where 4 of the bits are to the right of the
binary point, what does the binary value 00000001 represent?
0000.0001
=>
1/16
=> 0.0625
Show the 3 parts of the single
precision floating point
representation of the value 7/8.
Show the 3 parts of the single
precision floating point
representation of the value 7/8.
7/8 is 0.111
which is 1.11 x 2^(-1)
Sign: 0
Exponent: 126 (-1 in excess 127 format)
Fraction: 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Given the 32-bit floating point value -13.0
a.What are the values of the sign, exponent, and mantissa in
binary?
b.What is the hexadecimal representation of this number?
Given the 32-bit floating point value -13.0
What are the values of the sign, exponent, and mantissa in binary?
1101 * 2^0 => 1.101 * 2^3
sign: 1
exponent: 10000010
mantissa: 10100000000000000000000
What is the hexadecimal representation of this number?
0xc1500000
How many bits are required to represent a value
that can have a range from 0 to 13?
How many bits are required to represent a value that
can have a range from 0 to 13?
0 .. 1
0 .. 3
0 .. 7
0 .. 15
1 bit
2 bits
3 bits
4 bits
4 bits are required
A telephone number is composed of an area code, prefix, and line number.
In addition, a one bit flag is included with the phone number to indicate
whether or not the phone number is assigned to a customer.
The layout of this information is shown in the following figure.
BYTE
BIT
3
31 30 29 28 27 26 25 24
Word
Offset
0
A
u n u s
Fields in Data
area code
prefix
line
assigned
10 bits
10 bits
15 bits
1 bit
e d
2
23 22 21 20 19 18 17 16
p r
e f
1
15 14 13 12 11 10 9 8
i
x
l i
n e
a r
n u
0
7 6 5 4 3 2 1 0
e a
c o d e
m b e r
Byte
Offset
0
4
struct PhoneNumber
{
unsigned int areaCode : 10;
unsigned int prefix : 10;
unsigned int reserved : 11;
unsigned int assigned : 1;
unsigned short lineNumber : 15;
}
Download