Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
0b000100001110010110000010011001010x10e58265283476581Create 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 int s), 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:
Ob00000000000000000000000000010000000x0000002032
0b000000000000000000000000000111001
0b00000000000000000000000000010110010000000059,89
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 +,cdots,**,, 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: ,&,1,???,, and (comparison operators are allowed as well). All of the inputs are
unsigned int s(32-bit unsigned integers), and the output should be exactly the same as if you had used the,+-, and * operators on these
unsigned int s.
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 int s), 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
0b0000000000000000000000000000100000, ex0000002032
0b000000000000000000000000001110010x0000003957
Ob00000000000000000000000001011001Ox00000005989
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: ,&,hat(,),, and (comparison operators are allowed as well). All of the inputs are
unsigned int s (32-bit unsigned integers), and the output should be exactly the same as if you had used the,+-, and * operators on these
unsign
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

Recommended Textbook for

More Books

Students also viewed these Databases questions