CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm

Similar documents
CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm Solutions

CIS 2107 Computer Systems and Low-Level Programming Fall 2010 Midterm

CIS 2107 Computer Systems and Low-Level Programming Spring 2012 Final

Portland State University. CS201 Section 5. Midterm Exam. Fall 2018

COMP2611: Computer Organization. Data Representation

Computer Systems Programming. Practice Midterm. Name:

CMSC 313 Fall2009 Midterm Exam 1 Section 01 October 12, 2009

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Contents of Lecture 3

ECE264 Fall 2013 Exam 3, November 20, 2013

MIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max

Inf2C - Computer Systems Lecture 2 Data Representation

CS , Fall 2002 Exam 1

CS , Fall 2001 Exam 1

Exercise Session 2 Simon Gerber

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

211: Computer Architecture Summer 2016

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

The type of all data used in a C (or C++) program must be specified

15213 Recitation 2: Floating Point

Chapter 3: Arithmetic for Computers

CS101 Lecture 04: Binary Arithmetic

EECS 213 Fall 2007 Midterm Exam

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

CS 33. Data Representation (Part 3) CS33 Intro to Computer Systems VIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

The type of all data used in a C++ program must be specified

unused unused unused unused unused unused

A Fast Review of C Essentials Part I

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College September 6, 2018

COMP1917 Computing 1 Written Exam Sample Questions

COMP2121: Microprocessors and Interfacing. Number Systems

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Chapter 4: Data Representations

Signed umbers. Sign/Magnitude otation

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

C for Java Programmers 1. Last Week. Overview of the differences between C and Java. The C language (keywords, types, functies, etc.

Declaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.

Department of Electrical Engineering and Computer Sciences Spring 2007 Instructor: Dr. Dan Garcia

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Introduction to Computers and Programming. Numeric Values

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

Dynamic Memory Allocation and Command-line Arguments

Floating Point Arithmetic

CS & IT Conversions. Magnitude 10,000 1,

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

M1 Computers and Data

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation


CSE 1320 INTERMEDIATE PROGRAMMING - OVERVIEW AND DATA TYPES

EL2310 Scientific Programming

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

C mini reference. 5 Binary numbers 12

Computer Organization & Systems Exam I Example Questions

Problem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal.

Do not start the test until instructed to do so!

Creating, Compiling and Executing

Foundation Exam - Sample Problems for New Topics

CS , Spring 2004 Exam 1

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

15-213, Fall 2007 Midterm Exam

Question 4: a. We want to store a binary encoding of the 150 original Pokemon. How many bits do we need to use?

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

Final exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Dec 20, Student's name: Student ID:

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

Question Points Score Total: 100

CS 61C: Great Ideas in Computer Architecture. (Brief) Review Lecture

Lecture 3: C Programm

ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee

9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

231 Spring Final Exam Name:

Selection from Susta:Computer System Structures & John Loomis: Computer organization & M.Mudawar:Computer Architecture & Assembly Language. Cvičení 1.

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VIII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

System Programming CISC 360. Floating Point September 16, 2008

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Survey. Motivation 29.5 / 40 class is required

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

Data Representation and Storage. Some definitions (in C)

COMP Overview of Tutorial #2

Name: Login: cs61c- Decimal Ternary 5 12 three three

Type (1A) Young Won Lim 2/17/18

Chapter 2 Bits, Data Types, and Operations

Computer Science Foundation Exam

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College January 27, 2015

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

On a 64-bit CPU. Size/Range vary by CPU model and Word size.

CS Programming In C

DEPARTMENT OF MATHS, MJ COLLEGE

A Level Computing. Contents. For the Exam:

Transcription:

Fall 2011 Name: Page Points Score 1 5 2 10 3 10 4 7 5 8 6 15 7 4 8 7 9 16 10 18 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc. For each of the questions of this quiz, you can assume the following sizes for C data types: type bytes char 1 short 2 int 4 long 8 float 4 double 8 void* 4 i

For the following questions, you can assume that my home directory is the jfiore directory. 1. Unix shell stuff. jfiore home 2107 stuff.txt... prog.c assign 01 02 files (1 point) (a) If I m in my home directory i.e., /home/jfiore, what command can I type in order to run the C compiler on prog.c, but not the linker? (1 point) (b) If I m in my home directory, what s the one command that I can type in order to create a files directory within the assignment 1 directory? (1 point) (c) What command can I type to see a list of all of the files in my current directory? (1 point) (d) If I m in my home directory, what s the one command that I can type to move prog.c to the files directory inside assignment 2? (1 point) (e) If I run the command gcc -E prog.c to run the preprocessor only on prog.c, what does the resulting file contain (i.e., how is it different from prog.c)? 1 of 11 exam continues...

2. Some conversions. (1 point) (a) 104 tbytes =? kbits (1 point) (b) 3 minutes =? microseconds (1 point) (c) 48 mbytes =? tbytes (1 point) (d) 128 mbytes =? kbits (1 point) (e) 1 hour =? nanoseconds (a) (b) (c) (d) (e) 3. Convert 246 10 to: (1 point) (a) base 2 (1 point) (b) base 16 (1 point) (a) 2 31 4. Using the approximation trick that we talked about in class, about how much are each of the following? (1 point) (b) 2 29 (1 point) (c) 2 43 (a) (b) (c) out of a possible 10 2 of 11 exam continues...

(2 points) 5. What is 111101011 2 + 11101110 2 in base 2? 1 1 1 1 0 1 0 1 1 2 + 1 1 1 0 1 1 1 0 2 (2 points) 6. What is 3967B7 16 + 2E67 16 in base 16? 3 9 6 7 B 7 16 + 2 E 6 7 16 7. data representation. For these questions, please remember to answer in hex, not binary. (1 point) (a) In hex, what is the smallest integer that can be represented by a 16-bit two s complement int? (1 point) (b) In hex, what is the largest integer that can be represented by a 16-bit two s complement int? (1 point) (c) In hex, what is the largest integer that can be represented by a 16-bit unsigned int? (a) (b) (1 point) (d) In hex, what is 1 as a 16-bit two s complement int? (c) (d) (2 points) 8. What is printed by the following? char x = 50; char signed_prod; unsigned char unsigned_prod; signed_prod = x*3; unsigned_prod = x*3; printf("%d\n", signed_prod); printf("%u\n", unsigned_prod); /* recall that %u means to print as unsigned */ out of a possible 10 3 of 11 exam continues...

(1 point) (a) x y 9. Some bit operations. If we have char x = 0x53, y = 0xF9;, what is the result of the following operations? Your answer must be in the form of exactly two hex digits 1. (a) (1 point) (b) x y (b) (1 point) (c) x<<2 (c) (1 point) (d) x (d) (1 point) (e) x&0x0f (e) (1 point) (f) x y (f) (1 point) (g) x&&1 (g) 1 Ignore the possibility of promotion to 32-bit ints. Behave as though we re living in the land of 8-bit arithmetic. out of a possible 7 4 of 11 exam continues...

(6 points) 10. For this question, we re doing 5-bit two s complement representation of integers. Fill in the empty boxes in the following table. Addition and subtraction should be performed based on the rules for 5-bit, two s complement arithmetic. Recall that in your book s notation, TMin is defined to be the smallest negative two s complement number that we can represent, and TMax is the largest positive one. Name Decimal Rep. Binary Rep. Zero 0 0 0000 n/a 6 n/a 5 n/a 1 1011 n/a 0 1010 TMax TMin TMin+2 TMax+2 11. If I have the following: int main(void) { int a=10; int b=20; int *p=&b; int *q=p; (*p)++; q++; and memory is laid out like this: q 1000 p 1004 b 1008 a 1012 (1 point) (a) a what do you see if you print: (1 point) (b) &a (a) (b) out of a possible 8 5 of 11 question 11 continues...

(1 point) (c) b (1 point) (d) &b (1 point) (e) p (1 point) (f) *p (1 point) (g) &p (1 point) (h) q (1 point) (i) *q (1 point) (j) &q (c) (d) (e) (f) (g) (h) (i) (j) 12. fun with floats (3 points) (a) How would we represent the number 191.6875 10 in fixed-point binary? (1 point) (b) Normalize your answer from part (a). (3 points) (c) How would 191.6875 10 be stored in a C 32-bit float variable? (Remember that for 32-bit floats, the bias value is 127.) out of a possible 15 6 of 11 exam continues...

13. Recognizing the value of a floating-point variable. In this question, consider 6-bit floating-point numbers. Two bits are used for the mantissa and 3 bits for the exponent. (1 point) (a) For a 3-bit exponent field, what is the bias? (3 points) (b) What floating-point value does the bit string 0 01 001 represent, where 0 is the sign bit, 01 is the mantissa and 001 is the exponent? Please show all work. out of a possible 4 7 of 11 exam continues...

14. Use the following code to answer the questions. 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 5 typedef struct { 6 int x; 7 int *p; 8 int A[3]; 9 } Stuff; 10 11 void func01(int[]); 12 void func02(char*); 13 void func03(char*); 14 void func04(stuff); 15 16 int main(void) { 17 int A[]={10,20,30}; 18 int i=40; 19 Stuff s; 20 char msg[100]; 21 22 s.x=50; 23 s.p=&i; 24 s.a[0]=60; 25 26 strcpy(msg, "aspirin"); 27 28 func01(a); 29 func02(msg); 30 func03(msg); 31 func04(s); 32 33 return 0; 34 } 35 36 void func01(int A[]) { 37 A[0]++; 38 } 39 40 void func02(char *s) { 41 strcpy(s, "half way there"); 42 } 43 44 void func03(char *s) { 45 s = malloc(10); 46 strcpy(s, "coffee"); 47 } 48 49 void func04(stuff s) { 50 s.x=5555; 51 *(s.p)=4040; 52 s.p=(int*)malloc(sizeof(int)); 53 *(s.p)=4444; 54 s.a[0]=6666; 55 } (1 point) (a) How many bytes are passed to the function func01( )? (1 point) (b) How many bytes are passed to the function func02( )? (1 point) (c) How many bytes are passed to the function func04( )? (a) (b) (c) (1 point) (d) A[0] What is the value of each of the following after func04( ) has been called? (1 point) (e) i (1 point) (f) s.x (1 point) (g) *(s.p) (d) (e) (f) (g) out of a possible 7 8 of 11 question 14 continues...

(1 point) (h) s.a[0] (1 point) (i) msg (What s the string?) (h) (7 points) 15. Write a function which is passed an int A[ ] of positive integers and A s length. The function returns the largest item in A. Do not use the [ ] operator. (i) 16. big-endian/little-endian (7 points) (a) Write a function called is big endian( ) which returns 1 if the machine running the function is big endian or 0 otherwise. out of a possible 16 9 of 11 question 16 continues...

(1 point) (b) If we re on a 32-bit little-endian machine and int x has the value 0x01234567, and x is stored starting at address 1000, what is the value of the byte stored at address 1002? (7 points) 17. Write a function caps( ) which is passed a string s. The function returns a copy of s, but with the first letter of each word capitalized. If s is NULL or if an error is encountered, the function returns NULL. It is up to the caller to free any memory allocated by caps( ). (10 points) 18. Write a program which reads text from STDIN until EOF is entered. The program prints the length of the longest word and the longest line in the file. (Be careful. You don t need to print the longest line and longest word just their length.) out of a possible 18 10 of 11 question 18 continues...

(extra space) 11 of 11 end of exam