Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 Description of Task As part of this assignment, you will be responsible for conversions between number representations and bitwise manipulations. The programming assignment should

1 Description of Task
As part of this assignment, you will be responsible for conversions between number representations and
bitwise manipulations. The programming assignment should be developed in Java, and your classes
must reside in the package cs250.hw1
Your program will be provided with 3 arguments at the command line. You are required to perform a
set of operations over these arguments. These operations have been broken up into tasks: the points
distribution for each task and the restrictions (and accompanying deductions) are specified in the
grading section of this assignment.
Command line execution: java cs250.hw1.Operations 0b1010110010x0x1590b0x'' Task 3:
Error checking:
A binary number should not contain anything other than a 0 or 1.
A decimal number should only comprise digits 0 through 9.
A hexadecimal number contains digits 0 through 9, and letter A through F either in lowercase
or uppercase.
Print true or false for every input and terminate if any are false. You should print all 3 regardless of any
input being invalid.
Note: Task 4-8 can be completed using built in java methods. Only use them to check your
answer. If you violate these restrictions, points will be deducted (up to 100%) as outlined in
the deductions section. You may use these built in java methods only to validate the
correctness of your own implementation.
Task 4:
Convert each of the input numbers into the corresponding number in other numbering systems. For
example, if the number is in binary, you should convert that number into their corresponding
representations in the decimal and hexadecimal numbering systems.
Recall: The nth digit from the right in base b is bn-1
Built in java function that you should not use: Integer.parseInt (num, radix);
Task 5:
For every number specified at the command line, you will compute that number's negative
representation in 1's complement. For example, if we give you 5 you will return -5 represented in 1's
complement. This will require you to first convert each of the input numbers into binary.
Recall: 1's complement is accomplished by flipping each bit in the binary representation i.e. a 1 becomes
a 0, and a 0 becomes a 1.
Built in java function that you should not use: num
Task 6:
For every number specified at the command line, you will compute that number's negative
representation in 2's complement. For example, if we give you 5 you will return -5 represented in 2's
complement. This will require you to first convert every number into binary. You can ignore any potential
overflow, meaning if we give you a 4-bit bitstring, you should return a 4-bit bitstring.
Recall: 2's comp is accomplished by applying 1's comp then adding 1.
Built in java function that you should not use: num +1
Task 7:
Compute the bitwise OR, AND, and XOR of the 3 numbers. This will require you to first convert every
number into binary. This will require that you have equal length bitstrings. Recall that front-padding
with 0's does not change the value of an unsigned binary number, so you can front-pad all binary
bitstrings with 0 before operating such that all 3 binary numbers are the same length as the longest
one. Recall:
OR: If either of the values is a 1 the result is a 1 otherwise it is a 0.
AND: If both values are 1 the result is 1 otherwise it is a 0.
XOR: If either of the values are 1 and they are not both 1 the value is a 1 otherwise it is a 0.
Built in java function that you should not use: num1| num2, num1 & num2, num1^ num2
Task 8:
Compute the bitwise left and right shift of the 3 numbers for 2 shifts. This will require you to first convert
every number into binary.
Recall:
Left Shift: This is accomplished by appending an x number of 0's. The output will be longer
than the input.
Right Shift: Accomplished by moving each digit to the right x times. The output binary string
will be shorter than the input. See lecture slides
Built in java function that you should not use: num12, num 1>>2
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

2. What potential barriers would you encourage Samuel to avoid?

Answered: 1 week ago