CS2110: Homework 2 solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

Overview
This assignment consists of 3 parts, all of which consist of problems related to datatypes, binary
numbers, and bitwise operations. As always, start early or you may run into problems.
Three java files with method headers which you are to complete:
1. HW2Bases.java
2. HW2BitVector.java
3. HW2Operations.java
Resources
Begin by reading Chapter 2 of your text (“Introduction to Computing Systems”). Already read it?
Read it again. No really, reading and understanding this chapter will prove to be a great advantage on
this homework. It will help you understand several of the topics we will cover later in the course.
Guide
lines
Time for some coding! Complete the methods given in the files HW2Bases.java, HW2BitVector.java,
and HW2Operations.java. All of the methods have javadocs indicating what they should do, so make
sure you read them carefully and follow the directions.
Evaluation note: We will be grading this on a system with JDK 7 installed. If we can’t compile
your code, you will receive a zero for the file that did not compile. This is mentioned in the
syllabus and there are no excuses.
NOTE:
Each file has its own set of rules and limitations on what you may and may not use, so please look at
the comments at the top of each file.
If you use anything that is banned, you will get no credit for that function. The point of this is to play
with bit operations and learn how they work. You will not have all of these fancy Java API functions
when we get to C programming.
Coding Guidelines for HW2
1. All bitmasks MUST be written in hexadecimal. This is the convention for masks and makes it
very easy for the programmer to understand the purpose of the mask. If you write a mask in any
other base you will lose points.
• GOOD: (num & 0xFFE0) >> 5 | (num & 0xF01F) << 2 ^ 0x1 • BAD: (num & 65504) >> 5 | (num & 61471) << 2 ^ 1 • Notice with the GOOD you can more easily tell what the line of code is doing. • Note the bolded parts are bitmasks! 2. Enter your name in the javadoc at the top of each file. Failure to do so will result in a point deduction! 3. Use HW2Tester to find out which functions worked part of the time, none of the time, or infinitely looped. The output only tells which functions need fixing, but a detailed log of what went wrong will be automatically generated as Results.log, which should be in the same directory as HW2Tester. Hints Remember that all numbers are stored in your computer as binary. When you perform operations such as System.out.println(), the computer does the translation into another base for you. All you need to do is tell the computer how you are representing your numbers, and how to interpret them. For example, you can specify 16 in decimal, octal, or hexadecimal like so: System.out.println(16); // decimal (base 10), the default System.out.println(020); // octal (base 8), precede the number with a zero System.out.println(0x10); // hexadecimal (base 16), precede the number with a “0x” You can also tell Java to print out your number in different bases using a method called printf. printf is the GRANDDADDY of all printing functions! When we get to C programming, you will be using it a lot. printf takes a variable number of arguments, the first of which is a format string. After the format string come the parameters. The formatting for the numbers is controlled by the format string. Example: System.out.printf("In decimal: %d", 16); System.out.printf("In octal: %o", 16); System.out.printf("In hexadecimal: %x", 16); The %d, %o, or %x get replaced by the parameter passed in. printf does not support printing the number out in binary. For more information about printf read http://en.wikipedia.org/wiki/Printf (temporary link: http://www.cplusplus.com/reference/clibrary/cstdio/printf/) Evaluation 1. Correctness of the output of your code 2. Implementation of code without banned operations 3. We will be running test cases of our own. Note that we will be using Java 7 to grade your code! Deliverables The file HW2Bases.java The file HW2Operations.java The file HW2BitVector.java Have Any Questions? Ask on piazza!