Question: Create a new file called bitmath.cpp . In this file, write a program that asks the user for an operation, collects its arguments ( which

Create a new file called bitmath.cpp. In this file, write a program that asks the user for an operation, collects its arguments (which are unsigned ints), then computes the result and prints all the numbers in binary, hexadecimal, and decimal.
[wendy@neverland lab3]$ ./bitmath
Operation:
add
First operand:
32
Second operand:
57
0b000000000000000000000000001000000x0000002032
0b000000000000000000000000001110010x0000003957
0b000000000000000000000000010110010x0000005989
You'll need to support four operations:
see This operation takes one operand, and simply prints it (example below).
add This operation takes two operands, prints both operands, then prints the result of adding the two operands together.
sub This operation behaves the same as add, but performs subtraction.
mul This operation behaves the same as add, but performs multiplication.
Sounds easy? There's a catch: You may not use any of the standard arithmetic operators. The characters +,-,*,/, and % may not appear anywhere in your program, and you can only use functions from the iostream, iomanip, and string headers. Implement your own arithmetic functions using the bitwise operators: ~, &,|,^,<<, and >>(comparison operators are allowed as well). All of the inputs are unsigned ints (32-bit unsigned integers), and the output should be exactly the same as if you had used the +,-, and * operators on these unsigned ints.
When printing, print leading zeros on your binary and hexadecimal numbers (these should always have 32 and 8 digits, respectively). Print two spaces between each representation of a number. The decimal representation should be left-aligned.
[wendy@neverland lab3]$ ./bitmath
Operation:
see
First operand:
283476581
0b000100001110010110000010011001010x10e58265283476581

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!