6 Pages

homework1_solution

Course: CPR E 211, Spring 2003
School: Iowa State
Rating:
 
 
 
 
 

Word Count: 872

Document Preview

1/13/05 Due: Assigned: 1/25/05 CprE 211 Spring 2005 Homework 1 Solution Last Name First Name Section _________________________ _________________________ _____________________ Remember, these homework exercises not only give you practice with course concepts, but also represent the types of questions you will be tested on in an exam. 1 Assigned: 1/13/05 Due: 1/25/05 1. Digital Logic Number Representation...

Register Now

Unformatted Document Excerpt

Coursehero >> Iowa >> Iowa State >> CPR E 211

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
1/13/05 Due: Assigned: 1/25/05 CprE 211 Spring 2005 Homework 1 Solution Last Name First Name Section _________________________ _________________________ _____________________ Remember, these homework exercises not only give you practice with course concepts, but also represent the types of questions you will be tested on in an exam. 1 Assigned: 1/13/05 Due: 1/25/05 1. Digital Logic Number Representation [14] Consider each of the following data items, and fill in the blanks. a. Character `a' (ASCII character code) = ___0x61_________ Hex (8-bit) b. Character `A' (ASCII character code) = _____01000001_______ Binary (8-bit) c. Character `1' (ASCII character code) = _______0x31_____ Hex (8-bit) d. Character `1'(ASCII character code) = _______49_____ Decimal e. Integer 23 = ________17____ Hex (8-bit) f. 32-bit Unsigned Integer Range = _______0_____ - ___4,294,967,295____ Decimal g. 32-bit Unsigned Integer Range = _____0_______ - _____FFFFFFFF___ Hex h. 32-bit Signed 2's Complement Integer Range = ______-2147483648___ - ______2147483647_ Decimal i. (Unsigned) 0xA23C + 0x1EF0 = _____0xC12C____ Hex j. (Unsigned) 0xA23C - 0x1EF0 = _______0x834C___ Hex k. (Signed 2's Complement) 0xA23C - 0x1EF0 = __0x834C_____ Hex l. 368 Decimal = _____0x170___ Hex (16-bit) m. Logical shift right, 4 times, of 368 Decimal = ______23____ Decimal (16-bit) n. Bitwise AND of 368 Decimal with 231 Decimal = ____96_____ Decimal (16-bit) 2 Assigned: 1/13/05 Due: 1/25/05 2. Bitwise Operations [4] Complete the following: a. if (byVal & 0xC3) What does this statement test for? Check if any bits of 0,1,6 or 7 of byVal is 1 b. if (~byVal & 0xC3) What does this statement test for? Check if any bits of 0,1,6 or 7 of byVal is 0 c. if ((byVal & 0xC3) == 0x81) What does this statement test for? Check if byVal is equal to 10xxxx01, x can be 0 and 1 d. if ((byVal & 0xC0) && (byVal & 0x03)) What does this statement test for? Check if at least one of bits 6 and 7 AND at least one of bits 0 and 1 is 1 3. Consider the C code fragments and questions in d. and e., and fill in the blanks [6]. a. [1] short byKey, Row, Col; ... byKey = 0x1C; ... Row = byKey & 0x07; Col = (byKey & 0x38) >> 3; What is the value of Row (stated as a decimal number): _________4_ What is the value of Col (stated as a decimal number): _________3_ 3 Assigned: 1/13/05 Due: 1/25/05 b. [1] char byInput; ... if ( ( byInput & 0x01 ) || ( byInput & 0x20 ) ) If byInput = 0x64, is the condition TRUE or FALSE? __TRUE____________ (Recall that || is logical OR.) c. [2] Using if-else statements in C, write a code fragment that implements the following behavior: If either bit 2 or 5 of byVal (a char variable) is equal to 1, then call function Increase_Threshold(); or if bit 3 = 1 and bit 4 = 0, call function Decrease_Threshold(); otherwise call function Book_Keeping(). if(byVal&0x24) {Increase_Threshold();} else if((byVal&0x08)&&!(byVal&0x10)) {Decrease_Threshold();} else {Book_Keeping();} d. [2] Using bit-level and shift and logical operations and for loop statement, write a C program to count the number of 1's in variable x of "unsigned short" type. unsigned short x; int count=0; for(int i=0; i<=15; i++) { if(x&0x01) { count++; } x>>1; } 4 Assigned: 1/13/05 Due: 1/25/05 4. C Programming [4] a. [1] Write a C expression that will yield a word consisting of the odd bits of x, and the even bits of y. For operands x = 0x21212121 and y = 0x12121212, this would give 0x03030303. Assume a word is four bytes. (x&0x55555555)|(y&0xAAAAAAAA) b. [1] Given the following function prototype in C, answer i. iv. below: unsigned char Read_Results (char * pResults, char byArray[], int pos); i. ii. What is the size in bytes of the return value of the function? _____1 byte____ What is the size in bytes of each of the parameters passed to the function? ____width of memory_____ char *pResults ____width of memory____ char byArray[] ____vary___ int pos (No credits for these questions are taken off if you are wrong. You can consider they are all 4 bytes here) iii. Write a C statement that reads the data at address (pResults+pos) and assigns it to the element of byArray at position pos. ByArray[0]=*(pResult+pos) iv. Write a C statement that clears bit 7 of the data at address (pResults+pos). *(pResult+pos)&0x7F c. [2] You just started working for a company that is implementing a set of procedures to operate on a data structure where four signed bytes are packed into a 32-bit unsigned. Bytes within the word are numbered from 0 (least significant) to 3 (most significant). 5 Assigned: 1/13/05 Due: 1/25/05 You have been assigned the task of implementing a function for a machine using two'scomplement arithmetic and arithmetic right shifts with the following prototype: /* Declaration of data type where 4 bytes are packed into an unsigned */ typedef unsigned packed_t; /* Write a new value into a dataword */ dataward replace_byte (packed_t dataword, int bytenum, char byteval); That is, the function will replace the designated byte with a new value in byteval and return the result. The original dataword is unchanged. packet_t replace_byte(packet_t dataword, int bytenum, char byteVal) { packet_t temp=dataword&(~(0xFF<<(bytenum*8))); return(temp|(byteVal<<(bytenum*8))); } 5. Embedded Programming [3] a. Rank the following languages in order of their "level of abstraction" for the programmer, where 1 is the lowest level of abstraction. Hint: what does abstraction mean? _2____ Assembly language _1____ Machine language _4____ Object-oriented high-level language (e.g., C++, Java) _3____ High-level language (e.g., C, Pascal) _5____ Application-level language (e.g., Microsoft Excel macros) b. In embedded programming, how may abstraction help program design? Abstraction makes programming and debugging easy, it easy to manage the complexity of the problem. c. In embedded programming, how may abstraction hurt program implementation? It adds unnecessary low-level code and hurts performance (speed) 6
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Berkeley - CE - 70
University of California, Berkeley Civil Engineering 70Professor Ken Johnson Engineering GeologyCivil Engineering 70 Lecture 69/13/07Goals oWhat sediment is How is it described How is it formed How is it Moved o Sediment Character is link
Iowa State - CPR E - 211
Assigned: 3/1/05Due: 3/10/05CprE 211 Spring 2005 Homework 3Remember, these homework exercises not only give you practice with course concepts, but also represent the types of questions you will be tested on in an exam. I. Answer the following s
Berkeley - CE - 70
University of California, Berkeley Civil Engineering 70Professor Ken Johnson Engineering GeologyCivil Engineering 70 Lecture 79/18/07Metamorphic Rocks Metamorphic Grade / Facies Classification Foliation Regional versus contact Pressure / Tempe
Iowa State - EE - 324
6.66 The first one is the zeros of the system, the second one is the roots of the system. (a) ans = 0 + 1.4142i 0 - 1.4142i ans = -2.5468 0.2734 + 0.5638i 0.2734 - 0.5638i (b) ans = -1.0000 0.5000 + 0.8660i 0.5000 - 0.8660i ans = 0.0000 + 1.0000i 0.0
Iowa State - EE - 324
a)Bode Diagram 20 0 Magnitude (dB) Phase (deg) -20 -40 -60 -80 0 -45 -90 -135 -180 10-210-1100101102103Frequency (rad/sec)b)Bode Diagram 150 100 Magnitude (dB) Phase (deg) 50 0 -50 -100 -120-150-180 10-210-110
Iowa State - EE - 324
6.53 clear; x=linspace(-20, 20, 100); y1=abs(x)./(abs(x-10).*i+1).*abs(x+10).*i+1); subplot(3,1,1); plot(x,y1); y2=abs(x+4).*i).*abs(x-4).*i)./abs(x.*i+1); subplot(3,1,2); plot(x,y2); y3=abs(x.*i-1)./abs(x.*i+1); subplot(3,1,3); plot(x,y3);10.50
Iowa State - CPR E - 211
Assigned: 4/13/05Completed by: 4/20/05CprE 211 Spring 2005 Homework 5 SolutionLast Name First Name Section_ __Grading Procedure for Homework: This homework will not be collected and not be graded. The solution will be distributed on-line o
Iowa State - CPR E - 211
Assigned: 4/26/05Completed by: 4/29/05CprE 211 Spring 2005 Homework 6Grading Procedure for Homework: This homework will not be collected and not be graded. The solution will be distributed on-line one week later. Remember, these homework exerci
Iowa State - EE - 324
EE 324 Fall 2002 Final aName:_Score: Problem # 1 2 3 4 5Points 20 20 20 20 20 100Score1EE 324 Fall 2002 Final a 1. a)x tSampling Theory The signal given below is sampled at a rate of 10 kHz.3cos 5000 t D 2 sin 7500 t tWhat is the Ny
Iowa State - IE - 305
Dylan Reid IE 305 Spring 2007 Stocks Homework Answer SheetInstructor: Dave Sly Due: Thursday, April 19th, 20071)For each of the stocks, find the opening stock price in Jan 1, 2003 (or near that) and then the price today. Now compute the average
Iowa State - EE - 324
Iowa State - EE - 324
Iowa State - CPR E - 211
Assigned: 3/23/05Due: 3/29/05CprE 211 Spring 2005 Homework 4 SolutionRemember, these homework exercises not only give you practice with course concepts, but also represent the types of questions you will be tested on in an exam.I. C control s
Iowa State - IE - 305
Dylan Reid IE 305 Spring 2007 Homework: Chapter 2 Answer Sheet Instructor: Dave Sly_ Due: Thursday, April 19th, 20072.1 assets)_$1,100,000_ liabilities) )_$1,100,000_ WC) _$220,000_ Equity) _$250,000_ EPS) _50_ Price) _$15_l)_2.3 a) _ b) _ c)_
Iowa State - EE - 324
Given an LTI system:h n1 MMn kk 1a. Find the system frequency response of this system, put the result in phase-magnitude form. b. Find the system response, y[n], to the input:x nA cos0nc. What type of filter is this system? (low-
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Virginia Tech - SOC - 1004
SOC 1004spring 2008Neal KingTuesday, January 29, 2008Rituals generate solidarity and thus sustain groups. The most potent rituals focus on sacrifices made for the group. Groups transform grief into solidarity by engaging in rituals th
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
(39)Exam 4
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Iowa State - EE - 201
Berkeley - CE - 70
University of California, Berkeley Civil Engineering 70Professor Ken Johnson Engineering GeologyCivil Engineering 70 Lecture 89/20/07Deformation Styles o Rock Testing o Faulting versus Folding o Fold Terminology o Strike and Dip o Geology is 3
Michigan - CHEM - 125
Team #2 Patrick, Chirag, Carina, Stan Discussion Question # 1 Is it possible to predict if a precipitate will be white or a color other than white based on the position of the cation's element in the Periiodic Table? Organize the class data (part 2