Computer Systems Programming. Practice Midterm. Name:

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

COMP2611: Computer Organization. Data Representation

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

Data Types. Data Types. Integer Types. Signed Integers

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Jin-Soo Kim Systems Software & Architecture Lab. Seoul National University. Integers. Spring 2019

Computer System and programming in C

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #3: Of Integers and Endians (pt. 2)

ECE232: Hardware Organization and Design

Full Name: CISC 360, Fall 2008 Example of Exam

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

15213 Recitation 2: Floating Point

These are reserved words of the C language. For example int, float, if, else, for, while etc.

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

Computer Organization & Systems Exam I Example Questions

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

Representing Integers

CS16 Exam #1 7/17/ Minutes 100 Points total

Floating Point Arithmetic

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

211: Computer Architecture Summer 2016

CMPSCI 145 MIDTERM #2 SPRING 2017 April 7, 2017 Professor William T. Verts NAME PROBLEM SCORE POINTS GRAND TOTAL 100

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

Description Hex M E V smallest value > largest denormalized negative infinity number with hex representation 3BB0 ---

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

Number Representation

CS , Spring 2004 Exam 1

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

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

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

CS , Fall 2001 Exam 1

Byte Ordering. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Number Systems. Both numbers are positive

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

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Data Representation and Storage. Some definitions (in C)

Midterm Exam Answers Instructor: Randy Shepherd CSCI-UA.0201 Spring 2017

As stated earlier, the declaration

Programming in C++ 6. Floating point data types

a) Write the signed (two s complement) binary number in decimal: b) Write the unsigned binary number in hexadecimal:

Beginning C Programming for Engineers

1.3b Type Conversion

CSE 220: Systems Programming

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

CSE 1320 INTERMEDIATE PROGRAMMING - OVERVIEW AND DATA TYPES

Byte Ordering. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

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

CS101 Introduction to computing Floating Point Numbers

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

ECE 30 Introduction to Computer Engineering

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

CSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI.

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

Programming refresher and intro to C programming

Page 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10?

Getting started with Java

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

Numeric Encodings Prof. James L. Frankel Harvard University

Programming & Data Structure: CS Section - 1/A DO NOT POWER ON THE MACHINE

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

Floating Point Numbers

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Real Numbers finite subset real numbers floating point numbers Scientific Notation fixed point numbers

ECE2049: Homework 1. Consider the following code to compute the average of your exam grades: #define NUM_EXAMS (3)

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,...

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

15-213, Fall 2007 Midterm Exam

UNIT 7A Data Representation: Numbers and Text. Digital Data

CprE 281: Digital Logic

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

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

SIGNED AND UNSIGNED SYSTEMS

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

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

DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Computer Systems Principles. C Pointers

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

THE FUNDAMENTAL DATA TYPES

Introduction to Computers and Programming. Numeric Values

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

COMP Overview of Tutorial #2

Computer Organisation CS303

Data Representation Floating Point

Bits, Bytes and Integers

Floating Point Arithmetic

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

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

Arithmetic and Bitwise Operations on Binary Data

Data Representation Floating Point

ICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2

Basic data types. Building blocks of computation

Representing and Manipulating Floating Points. Jo, Heeseung

M1 Computers and Data

Inf2C - Computer Systems Lecture 2 Data Representation

Midterm Exam Review Slides

Integers and Floating Point

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

ECE2049 HW #1-- C programming and Binary Number Representations (DUE 1/19/2018 At the BEGINNING of class)

Transcription:

Computer Systems Programming Practice Midterm Name:

1. (4 pts) (K&R Ch 1-4) What is the output of the following C code? main() { int i = 6; int j = -35; printf( %d %d\n,i++, ++j); i = i << 3; j = j >> 4; printf( %d %d\n,i,j); 2. (2 pts) (B&O Ch. 1,7) a) What style of linking produces binaries that are self-contained and contain no references to code in the file system? b) Which step in the compilation process will take C progams and produce expanded C programs for the compiler? 3. (4 pts) (B&O Ch. 7, Problem 7.1) Consider the following program: int init=5; int x; main() { int y=0; y = x+init; return y; a. What section of the binary would contain variable x? b. What section of the binary would contain the code for main? 4. (4 pts) (B&O Ch. 2.1, Problem 2.4) a) 0x637a + 0x3a = b) 0x63a0 0x45 =

5. (12 pts) (B&O Ch. 2.1, Problems 2.1, 2.3) a) Convert 153 from decimal to binary b) Convert AE from hexadecimal to binary c) Convert 186 from decimal to hexadecimal d) Convert 10101110 from binary to hexadecimal e) Convert 01011011 from binary to decimal f) Convert DA from hexadecimal to decimal 6. (2 pts) (B&O Ch. 2.1, Problem 2.5) Consider this program: #include <stdio.h> int main() { int i=0x40302010; unsigned char *cp; cp = (unsigned char *) &i; printf("%x\n", *cp); a) What is its output on a little endian machine? b) What is its output on a big endian machine? 7. (4 pts) (B&O Ch. 2.1, Problem 2.12) Assuming x86-64, write a single C expression that takes a value x and returns x with its least significant two bytes set to 0. Use only the variable x and bit-wise operators. (i.e. Do not use = )

8. (10 pts) (B&O Chapter 2.1, Problem 2.8, 2.14) Fill in the result of the following expressions assuming the following declaration. unsigned char a=0xb5; unsigned char b=0x36; unsigned char c=0x00; Give all answers in hexadecimal notation. Note that logical operations return 0x1 or 0x0. a) ( a & b ) b) ( a ^ b ) c) ( a b ) d) ~c e)!c 9. (16 pts) (B&O Chapter 2.2, Problem 2.17, 2.19, 2.22) a) Represent the number 5 in a 4-bit two s complement format b) Represent the number 5 in a 4-bit two s complement format c) Consider the 5-bit two s complement number 10110, what is its decimal value? d) Consider the 5-bit unsigned number 10110, what is its decimal value? e) Give the hex representation of the largest positive 32-bit two s complement number. f) Give the hex representation of the most negative 32-bit two s complement number. g) Write the hexadecimal value of the 8-bit signed integer 13 h) Write the hexadecimal value of the 32-bit signed integer -13

10. (4 pts) (B&O Chapter 2.2, Problem 2.21) For expressions that mix signed and unsigned numbers, C will cast the signed value to an unsigned one before evaluation. In C, list whether the following expressions are true or false. a) ( 0U < -1 ) b) (unsigned) -3 > -35 11. (4 pts) (B&O Chapter 2.2, Problem 2.23) For these 32-bit data objects: i nt x = 0x88888888; unsi gned i nt ux = 0x88888888; a) What is the hexadecimal value of ( x << 20) >> 20? b) What is the hexadecimal value of ( ux << 20) >> 20? 12. (4 pts) (Chapter 2.2, Problem 2.26) Type errors can cause problems in programs. One common bug relates to the mixing of unsigned data types like size_t with signed integer types. With this in mind, what is the output of the following program: #include <string.h> /* size_t strlen(const char* str); */ int strshorter(char *s, char *t) { return (strlen(s) - strlen(t)) < 0; main() { if (strshorter( foo, bar )) printf( foo < bar\n ); if (strshorter( bar, food )) printf( bar < food\n ); if (strshorter( food, bar )) printf( food < bar\n );

13. (6 pts) (B&O Chapter 2.3, Problem 2.29) a) What is the decimal value of the sum of the following 6-bit two s complement numbers? 100110+100101 b) What is the decimal value of the sum of the following 6-bit two s complement numbers? 111101+011101 c) What is the decimal value of the sum of the following 6-bit two s complement numbers? 011001+011101 14. (4 pts) (Chapter 2.3, Problem 2.40) Suppose we are given the task of generating code to multiply integer variable x by various different constant factors K. To be efficient we want to use only the operations +, -, and <<. For the following values of K, write C expressions to perform the multiplication using at most three operations per expression. a) K=63 b) K=48 15. (4 pts) (Chapter 2.4, Problem 2.45) 27 a) Write the following fraction as a binary number using a binary point. 32 b) Write the fractional value of the following binary number 11.1011 16. (4 pts) (Chapter 2.4, Problem 2.54) Assume variable i of type int. For the following C expressions, state whether it will always be true or give a value such that it is not true. a) i == (int) (float) i; b) i == (int) (double) i;

17. (12 pts) (Chapter 2.4, Problem 2.47) Consider an IEEE-based floating point format below with one sign bit, four exponent bits, and two fraction bits. The exponent has a Bias of 7. Recall, an exponent of all 0s denotes a denormalized number while an exponent of all 1s denotes infinite/nan values. +---+-------------+----------+ s e3 e2 e1 e0 f2 f1 f0 +---+-------------+----------+ a) Give the bit-representation of the smallest, non-zero, positive number in this format. b) What is the value of this number given as a fraction? c) Give the bit-representation of the largest, non-infinite, positive number in this format. d) What is the value of this number? e) In this format, calculate the value the following bit representation: 0 0000 101 f) In this format, calculate the value the following bit representation: 0 1010 111