111CMSC 212 – S07 (lect 13)AnnouncementsProgram #3– Is on the webExam #1 – Today, 6:00 – 7:30 in Armory 0126Reading– Notes (Today)– Chapter 16 (Tuesday)2CMSC 212 – S07 (lect 13)Building a Test SuiteAPI:– Int createEmployee(char *lastName, char *firstName);• Return unique id for that employee– Int lookupEmloyee(char *lastName, char *firstName, in *id);• Return 0 on success, -1 on failure (not found or > 1 match)• Fills out id on success• fristName can be null– Int deleteEmployee(int id);– Int setSalary(int id, float salary);223CMSC 212 – S07 (lect 13)Possible Test CasesInt createEmployee(char *lastName, char *firstName);– Pass valid data– Pass same last name, different first name– Pass same last name, first name same as previous– Pass null for lastName and/or for firstName– Pass an lastName/firstName that has 10MB before null termination.– Create 10,000 employees4CMSC 212 – S07 (lect 13)Test Cases ContinuedInt lookupEmloyee(char *lastName, char *firstName, in *id);– Call before inserting anyone– Lookup someone that was created– Lookup someone with the same lastname, but different firstName– Lookup null last/first names– Pass id as nullInt deleteEmployee(int id);– Pass valid id– Pass invalid id– Pass id of someone who has just been deletedInt setSalary(int id, float salary);– Invalid id– Negative salary335CMSC 212 – S07 (lect 13)Representing CharactersNeed– Represent common characters– Have standards so computers can interoperateCommon Formats– ASCII• 7 bits for characters (stored in 8 bits normally) • most commonly used– UNICODE• family of encodings 8, 16, and 32 bits/character• allow greater variety of characters• Able to represent virtually character in use today– and some no longer in use6CMSC 212 – S07 (lect 13)ASCIIRepresents normal characters on US keyboards– A-Z (101-132)– a-z (141-172)– 0-9 (60-71)– punctuation: !@#$%^&*()_+-=[]{}|\;:"'<>?,./– space– <control-A> - <control-Z>• Also have other names <control-M> is CR (\r)447CMSC 212 – S07 (lect 13)UNICODEUnicode Representations– UTF-32 32 bit representation of all characters• all characters are the same size• wastes lots of space (2x UTF-16 for most things, 4x asciifor many things)– UTF-16 16 bit representation of characters• some characters are stored in two-character forms• popular since most things can be represented in 16 bits– UTF-8 8 bit representation of characters• provides backwards compatibility with ascii– low 7 bits are exactly ASCII– high bit on indicates part of UNICODE extensions• popular for web and other applications8CMSC 212 – S07 (lect 13)Representing IntegersAll data stored in binary– all numbers are 0 or 1Unsigned numbers are stored using base 2– possible range 0 to (2n-1) where n is the number of bitsSigned numbers are stored using two's complement– left most bit indicates if a number is positive or negative• 0 is positive• 1 is a negative number128163264128 4559CMSC 212 – S07 (lect 13)Adding Binary NumbersRepresenting unsigned integersthat don’t have a fixed widthAdd starting from rightCarry if the number is too large to represent – if it is greater than 11001 1001 1011 1101+ 10 + 11 + 11 +111------- ------- ------ ------10CMSC 212 – S07 (lect 13)2's complement representationTo compute a negative value:– flip all the bits of the positive value, add 1Allows addition of signed and unsigned numbersValid range of numbers– -2n-1 to 2n-1-1 for n bits– Example: 16 bit number -32,768 to 32,7676611CMSC 212 – S07 (lect 13)How do we represent real numbers?Each number has two parts– mantissa (represents a number between -1 and 1)• represented as a binary number i.e. 0.1 = ½– exponent (designates the position of the decimal point)• uses normal two's complement form• or bias offset– number = m r e where r is the radix• 6132.789 = +0.6132789 x 104Normalization– convert to number between -1 and 1– if the most significant digit of mantissa is non-zero.12CMSC 212 – S07 (lect 13)Floating Point ContinuedComputers normally use a radix of 2Examples of floating point numbers– 9.7510= 1001.112-> mantissa = 1001110 & exponent = 4 – 10.510= 1010.12-> mantissa = 10101 & exponent = 4– 7.45110= 111.0111002-> mantissa = 110111 & exp = 3IEEE Floating point standard– 32 bit floating point (float)• 1 sign bit, 8 bits exponent, 23 bits mantissa – 64 bit floating point (double)• 1 sign bit, 11 bits exponent, 52 bits mantissa• most common for real applications– 128 bit floating point (quad)• 1 sign bit, 15 bits exponent, 112 bits of
View Full Document