Unformatted text preview:

Q1.1: Base ConversionQ1.2: Number RepresentationQ1.3: Matrix AddressingOption 1: Matrix stored as 2D arrayPart APart BPart COption 2: Matrix stored as 1D arrayPart DPart EPart FQ2: Bit Manipulationbitmanip.cmain.cQ3: Splitsplit.csplit.hmain.cCS61C FA20 QuestInstructors: Dan Garcia, Borivje Nikolic Head TAs: Stephan Kaminsky, Cece McMahonQ1.1: Base ConversionFOR THIS ENTIRE SECTION, YOU ARE NOT ALLOWED TO USE THE C PROGRAMMING LAN-GUAGE AS A CALCULATOR (OR A CALCULATOR EITHER, FOR THAT MATTER).Convert 458to base 3Answer: ________Q1.2: Number RepresentationFOR THIS ENTIRE SECTION, YOU ARE NOT ALLOWED TO USE THE C PROGRAMMING LAN-GUAGE AS A CALCULATOR (OR A CALCULATOR EITHER, FOR THAT MATTER).How would you encode−18 using 6 bits in the following representations? WriteN/Aif it is impossible. Please write exactly6 bits – include any leading zeros if needed, and DO NOT include a leading 0b .Representation AnswerUnsigned ________One’s Complement ________Two’s Complement ________Sign-magnitude ________Bias (bias value: -31) ________Q1.3: Matrix AddressingFOR THIS ENTIRE SECTION, YOU ARE NOT ALLOWED TO USE THE C PROGRAMMING LAN-GUAGE AS A CALCULATOR (OR A CALCULATOR EITHER, FOR THAT MATTER).You need to answer Option 1 AND Option 2 for full credit on this part.Option 1: Matrix stored as 2D arrayA matrix representation stores its values (for this problem, only bytes) such that the offset address of the element in rowiand columnjcan be calculated by concatenating the binary representations ofiandj, where row and column indicies startfrom 0. The size of the bit fields for row and column number should be big enough to accommodate the highest possible rowand column numbers.The amount of space allocated for this array will be the maxiumum number of elementsthat can be represented by this bit field, even if we won’t use all of them.For example: A 3 (row) x 5 (column) matrix,A, will have a 2 bit row field and a 3 bit column field. The row bits will havevalues0b00through0b10(0-2), and the column bits will have values0b000through0b100(0-4). The element in row2 and column 3 will have an offset address of0b10011. The element in row 1 and column 2 will have an offset address0b01010.Even though this array only stores 15 bytes, space will allocated for 32 bytes due to the size of the5 bit wide field.Part AMatrixMhasmaxrows= 13 rows andmaxcols= 65 columns. Find the offset address of the element in rowrow= 7and columncol= 12. Put your answer in binary, without the leading0b, andwithout any leading zeros, so if wecalculated an offset address (from above) as 0b01010 , we would enter 1010 .Answer: 0b ________Part BWhich of the following C expressions will produce the desired result in Part A? (Choose one)• (maxrows << ceil(log2(maxcols))) & col• (row << floor(log2(maxcols))) | col• (row << ceil(log2(maxcols))) || col• (maxrows << ceil(log2(maxcols))) && col• (col << floor(log2(maxcols))) && row• (col << ceil(log2(maxcols))) | row• (row << ceil(log2(maxcols))) | col• (maxrows << ceil(log2(maxcols))) || col• (col << ceil(log2(maxcols))) || row• (col << ceil(log2(maxrows))) && rowPart CWhat integer would you pass tomallocwhen allocating space for matrixM, which only stores a byte per value in thematrix? (Yes, we know there might be a lot of wasted space.)Answer: ________Option 2: Matrix stored as 1D arrayAnother way of storing this array would be to store it in a column-major order one-dimensional array. A column-major orderone-dimensional array is an array in which the columns of the given matrix are stacked one after another in the array. Forexample, given the matrix below:1 2 34 5 67 8 9We would get the array [1,4,7,2,5,8,3,6,9]The amount of space allocated for an array is equivalent to the number of elements in the array. For example, if we wereto store a 3 x 5 matrix, we would only need to allocate space for 15 elements. The rows would be numbered 0-2, and thecolumns would be numbered 0-4.Part DRecall matrix hasmaxrows= 13 rows andmaxcols= 65 columns. Find the offset address of the element in rowrow= 7and column col = 12. Just write the integer value, no need to write it in binary.Answer: ________Part EWhich of the following C expressions will produce the desired result in Part D? (Choose one)• col + maxrows + row• row + maxcols + col• row + col• (col * maxrows) + row• (row * maxcols) + col• row + maxcolsPart FWhat integer would you pass tomallocwhen allocating space for matrixM, which only stores a byte per value in thematrix? (Yes, we know there might be a lot of wasted space.)Answer: ________Q2: Bit ManipulationWrite a functionbit_manipthat takes in an arbitrary 64-bit unsigned integer, and for everyN = 5set of bits startingfrom LSB (considering the number zero-extended to a multiple ofNbits), we rotate them right byR = 3bits and thenturn on bit 2 and turn off bit 1 (within each group of 5 bits) and then return the final value.As an example, if our input were a 16-bit number whose bits were0bABCDEFGHIJKLMPQSandN = 5, we rotate it right byR = 1 bit, and ON = 1 and OFF = 3 then:• 0bABCDEFGHIJKLMPQS . . . being thought of as groups of N = 5 bits would become• A BCDEF GHIJK LMPQS . . . then zero-extended to a multiple of N = 5 bits would become• 0000A BCDEF GHIJK LMPQS . . . after the rotate right by 1 bit, R = 1 , would become• A0000 FBCDE KGHIJ SLMPQ . . . after turning on bit ON = 1• A0010 FBC1E KGH1J SLM1Q . . . after turning off bit OFF = 3• A0010 F0C1E K0H1J S0M1Q . . . and returning the lowest 16 bits means we’d return. . .• 0b0F0C1EK0H1JS0M1QDownload the included files: (shown below)You may editmain.cto test your code. Do not edit thebit_manipsignature. You will only be submittingbit_manip.cand only the code in that file will be graded.bitmanip.c#include <inttypes.h>uint64_t bit_manip(uint64_t num) {//YOUR CODE HEREreturn 0;}main.c#include <inttypes.h>extern uint64_t bit_manip(uint64_t);int main(int argc, char *argv[]) {return 0;}Q3: SplitWrite a functionsplitthat takes a singly-linked list of words (strings of lower-cased characters terminated appropriately)and splits it into two new singly-linked lists based on whether thefirstletter of the word is a vowel (a, e, i, o, or u) orconsonant (everything else).All of the inital storage (nodes and strings) must be freed; you must copy strings tonew locations in memory. Also, the output list should keep the same relative ordering of the input strings.You must use CS61C_malloc() and CS61C_free()


View Full Document
Download Quest
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Quest and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Quest 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?