CS2630: Computer Organization Homework 1 Bits, bytes, and memory organization Due January 25, 2017, 11:59pm Instructions: Show your work. Correct answers with no work will not receive full credit. Whether you write or type (or both) your answers, save your work as a single PDF file. Upload it on ICON under Assignments > Homework 1. Physical paper copies are not accepted. Goals for this assignment Understand what information can be stored with bits Get comfortable with two s complement Enhance problem solving skills with bit level operations Learn about the organization of memory 1. The internet tells me there are 136 million items in the US Library of Congress. How many bits do you need to name each item uniquely? Assuming we only build an index of the items in US Library of Congress and do not concern ourselves with the real name of the items (which will be quite a pain to remember those words). We need an integer (an unsigned integer would be fine) to index the 136 million items. We need a space of this binary expression, which is a maximum amount of number this binary index can express. The space(possibilities) of N digit binary number is 2 N So 2 N > 136000000 then log 2 136000000 = 27.019031, then N >=28. You can also try calculating 2 28 to verify your result. 2. Using signed integers with two s complement encoding, what is the range of numbers (be precise about the endpoints) that can be represented using the given amount of bits. a. 5 bits b. three bytes (assume 8 bits per bite)
The range should be the most negative and the most positive number one can represent using certain bits. Note that one byte is 8 bits, 3 byte is 24 bits, and signed integer reserved the top bit for the sign. Then the available bit in each option would be 23 for three bytes and 4 for 5 bits. N Thus, for positive end, we have 0 followed by all 1 s, which is 2-1 ( to see this fact write the number 2 N in binary and subtract 1 from it) but for the negative end, we actually can have minus 2 N with 100000 0 (to check, subtract 1 more from 1000 0 and see that you get a positive number) So the range would be [- 2 N N, 2-1] Result: a. [-16, 15] b. [-8388608, 8388607] or in the original notation if you want 3. Convert the following numbers to binary using two s complement encoding. Use at least enough bits to store the entire number. a. -73 10 b. 1013 10 Using the flipping trick or other methods are all approved, as long as they are presented clearly. a. -73 10 = 10110111 (more leading 1 s optional) e.g., 73 / 64 = 1R9, 9/8 = 1R1, so we need one s in exactly the 64 s, 8 s and 1 s places for positive 73 01001001 (shown with leading zero to indicate positive) now invert and add 1 to get -73 01001001 10110110 + 1 10110111 b. 1013 10 = 0110101 1013/512 = 1R501, 501/256 = 1R245, 245/128 = 1R117, 117/64 = 1R53, 53/32 = 1R21, 21/16 = 1R5, 5/4 = 1R1 so we need one s in exactly the 512 s, 256 s, 128 s, 64 s, 32 s, 16 s, 4 s and 1 s places 011 0101(leading zero for positive)
4. Convert the following signed integers (they are shown in binary, two s complement) to decimal. a. 11001010 b. 10101001 Again, lots of ways to do this problem. We show one method. -1*128 + 1*64 + 0*32 + 0*16 + 1*8 + 0*4 + 1*2 + 0*1 = -54 a. 11001010 = -54 10-1*128 + 0*64 + 1*32 + 0*16 + 1*8 + 0*4 + 0*2 + 1*1 = -87 b. 10101001 = -87 10 5. Suppose we create a computer screen out of black/white pixels. Each row of the screen is controlled by a 4-bit number. For example, here we display a letter 0110 à a) Give the hexadecimal digits to display the letter S. (Since you choose the font, show your work!) b) What letter is displayed by entering F9F88 (leftmost digit is top row)? a) You choose the font, so anything looks like a S will do, and it should match the hex digits you wrote. One example is * * 1000 0001
0xF8F1F b) It looks most like a P 6. I hand you a 93 jelly beans and seven jars. You must find a way to distribute the beans into the jars, such that no matter what amount of jelly beans I ask you for (1-93), you can just hand me a combination of the jars (without opening them!) to give me the exact number. This is an interesting one. How do one manage to express any amount with a fixed set of number? Actually this is a mathematical question. And Mathematical question is hard! I for one, do not want to dive into that, so let s go with the safest solution that I can think of. Let s go with binary. Smaller problem first: for any number < 8, we can use some combination of 4,2,1 to express them. Now in this case, we have 93, but only 7 jars, so we can first have 1, 2, 4, 8, 16, 32, and that should give us any number < 64. That s for sure. Now we can express anything (<= 63) and we still have 93 63 = 30 remaining. But for those 30 numbers greater than 63, we can first place 30 beans in last jar. And then the range turn from [64, 93] to [34, 63]. Then we can assemble the leftover with what remains, and we can since the leftover is smaller than 64. Result: 1 2 4 8 16 32 30 7. Suppose I the cable company represents the channels your TV has access to with a 64- bit integer. Each channel from 0 to 63 is represented by one bit, where 1 means the channel is enabled and 0 means channel is disabled. Assume channel 0 is the least significant bit. When you get your cable box, the technician sets the 64-bit code. long A = enabledchannels(); Write code (pseudocode or Java is fine) for the following tasks. You may not call any magic library functions, rather you should just use basic operations like if, for, while, the bitwise operations (~, &, <<, >>,, ^) and integer operations, like ==, <, and >. a. A function that returns whether a particular channel (integer 0-63) is enabled. boolean isenabled(long A, int channel) { } b. A function that returns a new integer, with the given channel enabled. Long enablechannel(long A, int channel) { }
a) boolean isenabled(long A, int channel){ // id start from 0 so no need to minus one down there in the IF If ((A >> channel) && 1) == 1) return TRUE // all those 63 0s in the binary for 1 is to make sure no one else is in my consideration else return FALSE } END b) Long enablechannel (long A, int channel) { long B = 1 B<<channel // shifts 1 to the position of channel return (A B) // enables the channel as we are using OR operation } As long as the program executed by my logical mind give the right answer, you are good. 8. Suppose I have an architecture where the pointers hold 24-bit addresses. The architecture is byte-addressed (i.e., every byte has a unique address). a. How much memory can the computer have (assuming we must name every byte)? Name the amount using the right prefix (i.e., Kibi, Mebi, ). b. Suppose I have an array of 3 pointers. The first byte of the array is at address 0xF00004. What is the address of the last byte in the array? (draw a diagram if it helps) a. 2 24 bytes is 16 MebiByte. Why? Every byte needs a unique name because the machine is byte-addressed and we have 24 bits for addresses. b. 24 bits is 3 bytes, and every pointer is that long. 3 pointers give us 9 bytes and every byte needs an address, so we will give them one. So adding 9 to the starting address. 04 + 9-1 = 12 which is C in hex. The answer would be 0xF0000C. 04+9 gets us to the first byte after the array, subtracting 1 gets us to the very last byte in the array.