Question
In Java CANNOT USE ANY OF THE FOLLOWING! (1) Integer.parse or parseInt (2) Integer.toHexString (3) Integer.toBinaryString (4) Built in bitwise operations (~, ^, |, &,
In Java
CANNOT USE ANY OF THE FOLLOWING!
(1) Integer.parse or parseInt (2) Integer.toHexString (3) Integer.toBinaryString (4) Built in bitwise operations (~, ^, |, &, <<, >>) a. Note: Logical operations are allowed (!, ||, &&, etc.)
Task: 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: Compute the 1s complement (in binary) of every number that was specified at the command line. This will require you to first convert every number into binary. Recall: 1s 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: Compute the 2s complement (in binary) of every number that was specified at the command line. This will require you to first convert every number into binary. Recall: 2s comp is accomplished by applying 1s comp then adding 1. See lecture slides Built in java function that you should not use: ~num + 1
Task: Compute the bitwise OR, AND, and XOR of the 3 numbers. This will require you to first convert every number into binary. 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: 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 0s. See lecture slides Right Shift: Accomplished by moving each digit to the right x times. See lecture slides Built in java function that you should not use: num1<<2, num1>>2
Example argument: java cs280a1.hw1.Operations 15 0b1011 0xfa
Example output:
Task 4 Start=15,Binary=0b1111,Decimal=15,Hexadecimal=0xf Start=0b1011,Binary=0b1011,Decimal=11,Hexadecimal=0xb Start=0xfa,Binary=0b11111010,Decimal=250,Hexadecimal=0xfa Task 15=1111=>0000 0b1011=1011=>0100 0xfa=11111010=>00000101 Task 15=1111=>0001 0b1011=1011=>0101 0xfa=11111010=>00000110 Task 1111|1011|11111010=11111111 1111&1011&11111010=00001010 1111^1011^11111010=11111110 Task 1111<<2=111100,1111>>2=11 1011<<2=101100,1011>>2=10 11111010<<2=1111101000,11111010>>2=111110
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started