Computer Science Fundamentals

Description

159.102 Computer Science Fundamentals Assignment 2

You have been asked to write a C program that acts as a simple calculator.

The program prompts the user to type in an expression.

The user then types in: number1 (in hexadecimal) an instruction (2 or 3 characters) number2 (in hexadecimal).

There will be a single space before and after the instruction. The input will be correct. No verification is necessary.

All input numbers will be within the range 0x00 to 0xffffffff.

Use the type unsigned int for your numbers.

Use the %x format specifier to input and print hexadecimal values.

The instruction can be one of the following:

add add number1 to number2

sub subtract number2 from number1

and bitwise and of the two numbers

or bitwise or of the two numbers

xor bitwise exclusive or of the two numbers

shl shift the bits of number1, number2 places to the left

shr shift the bits of number1, number2 places to the right

asr arithmetic shift right the bits of number1, number2 places to the right (see below)

rol rotate the bits of number1, number2 places to the left (see below)

ror rotate the bits of number1, number2 places to the right

A one-bit arithmetic shift right, shifts each bit in the number one place to the right.

If the most significant bit of the original number is a 1,the most significant bit of the answer is set to 1, otherwise it is set to 0.

A one-bit rotation left shifts all the bits one place to the left, the most significant bit of the original number becomes the least

significant bit of the answer.

A one-bit rotation right shifts all the bits one place to the right, the least significant bit of the original number becomes the

most significant bit of the answer.

Be careful using the C operators >> and <<. (m >> n) is 'undefined' if n is greater than 31 10 .

(i.e. the answer could be a random value!, but is more likely to be (m >> n&0x1f))

Your program must work with any value of n. (Shift by 1 in a loop n times).

Examples:

Type in an expression: 49 add 41

The answer is: 8a

Type in an expression: 49 sub 41

The answer is: 8

Type in an expression: 2a xor 7d

The answer is: 57

Type in an expression: 49 ror 10

The answer is: 490000

Type in an expression: 80000002 asr 1

The answer is: c0000001

Make sure that your program compiles and links using gcc. Submit your assign2.c electronically.

Marks will be awarded on how many test cases your program handles correctly.

Test your program with different numerical values and instructions before submission.

Calculate the price of your order

Simple Order Process

Fill in the Order Form

Share all the assignment information. Including the instructions, provided reading materials, grading rubric, number of pages, the required formatting, deadline, and your academic level. Provide any information and announcements shared by the professor. Choose your preferred writer if you have one.

Get Your Order Assigned

Once we receive your order form, we will select the best writer from our pool of experts to fit your assignment.

Share More Data if Needed

You will receive a confirmation email when a writer has been assigned your task. The writer may contact you if they need any additional information or clarifications regarding your task

Let Our Essay Writer Do Their Job

Once you entrust us with your academic task, our skilled writers embark on creating your paper entirely from the ground up. Through rigorous research and unwavering commitment to your guidelines, our experts meticulously craft every aspect of your paper. Our process ensures that your essay is not only original but also aligned with your specific requirements, making certain that the final piece surpasses your expectations.

Quality Checks and Proofreading

Upon the completion of your paper, it undergoes a meticulous review by our dedicated Quality and Proofreading department. This crucial step ensures not only the originality of the content but also its alignment with the highest academic standards. Our seasoned experts conduct thorough checks, meticulously examining every facet of your paper, including grammar, structure, coherence, and proper citation. This comprehensive review process guarantees that the final product you receive not only meets our stringent quality benchmarks but also reflects your dedication to academic excellence.

Review and Download the Final Draft

If you find that any part of the paper does not meet the initial instructions, send it back to us with your feedback, and we will make the necessary adjustments.