ECE-1021

HOMEWORK #6

(Last Mod: 27 November 2010 21:38:42 )

ECE-1021 Home


PART A

Write and test the function GetV_u() and GetV_i() that get integer values from the keyboard. Each function takes a pointer as it's sole argument.

The first takes a pointer to a variable of type unsigned int while the second takes a pointer to a variable of type int.

The behavior of both functions is defined as follows:

  1. Each function should skip any leading white space characters.
  2. The GetV_i() function should recognize at most one negative sign anywhere within the leading white space group.
  3. Each function should then read and convert characters only if they are part of an integer value.
  4. Each function should stop upon encountering the first character that it cannot interpret as part of an integer value.
  5. The character that caused the read termination should be placed back in the stream buffer ( using ungetc() ).
  6. If no characters were successfully read, the value should default to zero.
  7. If the pointer passed to the function is not a NULL pointer, then the value read in should be stored at the location pointed to.
  8. The function should return the value that was read.

PART B

This part is to be done on paper and turned in at the beginning of the first class session after the homework Grace Period expires.

Work should be legible and neatly presented. The use of Engineering Paper (E-2 paper) is preferred. Answers should be clearly indicated.

The goal of this assignment is for you to gain proficiency in working with different number bases and number representations. As such, your work must reflect your ability to perform these operations, not the ability of the design team that developed your calculator. You may therefore use a calculator to perform base-10 computations only. Specifically, you may not use calculator functions that perform number base conversions or that permit you to work with numbers in any base other than decimal. You may use such functions to check your work only. You must show your work on all problems that require computation to receive credit.

Number Base Conversions

Using on the "systematic" methods described in the reading material, perform the following conversions. Do NOT perform brute force conversions - they will NOT receive credit.

Unsigned Integers

  1. 100,000 to hex

  2. 0x8F7C to decimal

  3. 1101 1010 0111b to decimal

  4. 57614 octal to decimal

  5. 254 to binary

  6. 0xF7B5 to binary

  7. 1000 1101 1111 0101b to decimal

  8. 4230135 to base-7

Fixed Point Values

  1. Represent the value π2 in decimal, hex, and binary to the six radix places.

  2. Represent the value 1/e in decimal, hex, and binary to the equivalent of at least six decimal places.

  3. Express the U.S. National Debt ( $7,418,151,165,657.99 as of 07 Oct 04) in hexadecimal.

Floating Point Values

  1. Represent the length of a meter, expressed in light years, using normalized exponential notation in decimal, hex, and binary. The mantissa should have enough digits to represent the number to an accuracy of 0.01%.

  2. Represent the value of Avogadro's Number, using normalized exponential notation in decimal, hex, and binary. The mantissa should have enough digits to represent the number to an accuracy of 0.001%.

Range Calculations

  1. What is the decimal value of the largest value that can be represented using 12 digits in base-5?

  2. How many hexadecimal digits are required to represent the speed of light, expressed in meters per second?

  3. The number of possible ways to shuffle a 52 deck of playing cards is 52! (52 factorial). How many bits would be required to express this value (i.e., how many digits in base-2)?

Arithmetic in Other Number Bases

Hexadecimal Arithmetic Tables

  1. Prepare hand-written Hexadecimal Addition and Multiplication Tables similar to that found in the reading for base-8. You may either prepare separate tables or a combined table.

Hexadecimal Arithmetic

Perform the following computations directly in hexadecimal. For the division problems, if the quotient is not an integer, show the result both in quotient/remainder form and also as a fixed point result to two hexadecimal places.

  1. 0xAE + 0x2C

  2. 0xAE - 0x2C

  3. 0xAE x 0x2C

  4. 0xAE / 0x2C

  5. 0xFACE + 0xDEED

  6. 0xFACE - 0xDEED

  7. 0xFACE x 0xDEED

  8. 0xFACE / 0xDEED