Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Bit-Level Integer Coding Rules: In several of the following problems, we will artificially restrict what programming constructs you can use to help you gain a

Bit-Level Integer Coding Rules:

In several of the following problems, we will artificially restrict what

programming constructs you can use to help you gain a better

understanding of the bit-level, logic, and arithmetic operations of C. In

answering these problems, your code must follow these rules:

1. Assumptions

Integers are represented in twos-complement form.

Right shifts of signed data are performed arithmetically.

Data type int is w bits long. For some of the problems, you will be given a specific value for w, but otherwise your code should work as long as w is a multiple of 8. You can use the expression sizeof(int)<<3 to compute w.

2. Forbidden

Conditionals (if or ?:), loops, switch statements, function calls, and macro invocations.

Division, modulus, and multiplication.

Relative comparison operators (<, >, <=, and >=).

3. Allowed operations

All bit-level and logic operations.

Left and right shifts, but only with shift amounts between 0 and w 1. Addition and subtraction.

Equality (==) and inequality (!=) tests. (Some of the problems do not allow these.)

Integer constants INT_MIN and INT_MAX.

Casting between data types int and unsigned, either explicitly or implicitly.

Write code for a function mul3div4 that, for integer argument x, computes (3 x/4) but follows the bit-level integer coding rules (see above). Your code should replicate the fact that the computation 3*x can cause overflow.

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

1. Diagnose and solve a transfer of training problem.

Answered: 1 week ago