ecse221_as1 - Department of Electrical and Computer...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Department of Electrical and Computer Engineering ECSE-221A Introduction to Computer Engineering I Assignment 1 – Data Representation Assigned: Monday, September 8th, 2003 Due: Monday, September 22, 2003 Assignments box, 6 th floor. Question 1 Computers with 64-bit register sizes are becoming increasingly more visible (e.g. Motorola P5, AMD Opteron, Intel Itanium). Although some “C” compilers support a 64-bit integer type (the aptly named longlong ), few implementations (libraries) have a provision for inputting numbers in the range [0, 2 64 -1]. Write a “C” language function that converts a hexadecimal string in the range [0,ffffffffffffffff] into a 64-bit unsigned integer according to the following prototype: int str2udoublelong (char *string, long *doublelong); Since not all compilers support the longlong datatype, the 64-bit integer will be represented as an array of 2 long integers where doublelong[1] corresponds to the most significant word, and doublelong[0] the least significant word. The function should return 0 if the conversion was successful and –1 otherwise (e.g. the input does not correspond to a valid hex string). You may use any functions in the standard “C” library. Your function should be able to handle variable length strings, e.g., 0xff, 0x123456789abcdef, etc. Validate your function be writing an appropriate test program. Exhaustive testing is not feasible, so you must determine an appropriate set of test cases that can provide reasonable assurance that the function will work correctly over the entire range of inputs. Question 2 Write a “C” language program that inputs a hexadecimal string corresponding to either a single or double precision IEEE floating point number and outputs the corresponding decimal floating point representation. The program has exactly 2 arguments: the first specifying either single or double precision and the second the string that is input to the program. Examples: C\ toieee –s 0x7effffff Single precision interpretation of 0x7effffff is 1.7014117e+038 C\ toieee –s 0xffff Single precision interpretation of 0xffff is 9.1834095e-041
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C\ toieee –d 0x7fefffffffffffff Double precision interpretation of 0x7effffffffffffff is 1.797693134862316e+308 Your program should generate appropriate error messages if the input string does not correspond to a valid hexadecimal number of if the options presented to the program are incorrect. It is also important that your results be displayed to appropriate precision given the respective mantissa sizes. As with Question 1, you are free to use any functions in the standard “C” library. To validate this program, compute the following by hand and compare against the program output: 1. The smallest single precision floating point number greater than zero. 2.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/01/2009 for the course ELEC ENG ECSE 221 taught by Professor Ferrie during the Fall '08 term at McGill.

Page1 / 13

ecse221_as1 - Department of Electrical and Computer...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online