Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programing Problems: (BIT MANUIPULATION) I am having trouble understanding how to code these problems for an assignment and I would appreciate a detailed explaination

C programing Problems: (BIT MANUIPULATION)

I am having trouble understanding how to code these problems for an assignment and I would appreciate a detailed explaination / step-by-step walk through for some of the easy ones to help me understand how it works.

You are expressly forbidden to: 1. Use any control constructs such as if, do, while, for, switch, etc. 2. Define or use any macros. 3. Define any additional functions in this file. 4. Call any functions. 5. Use any other operations, such as &&, ||, -, or ?: 6. Use any form of casting. 7. Use any data type other than int. This implies that you cannot use arrays, structs, or unions.

You may assume that your machine: 1. Uses 2s complement, 32-bit representations of integers. 2. Performs right shifts arithmetically. 3. Has unpredictable behavior when shifting an integer by more than the word size.

EXAMPLES OF ACCEPTABLE CODING STYLE: /* * pow2plus1 - returns 2^x + 1, where 0

/* * pow2plus4 - returns 2^x + 4, where 0

PROBLEMS:

image text in transcribed

I have been researching the operations in C but I do not fully understand "^" and "|" operations.

The answer to the first problem (evenbits) is supposedly:

int evenBits(void) {

int byte = 0x55;

int word = byte | byte

return word | word

}

I would appreciate an explaination of how this code works (and the other problems if you can do them) so I can master these and move on to the difficult problems. Thank you!

* evenBits -return word with all even-numbered bits set to 1 Legal ops:!&+ Max ops:8 Rating: 1 void) int evenBits ( return 2; * minusOne- return a value of -1 Legal ops:!&+ Max ops: 2 Rating: 1 1 void) int minusOne ( return 2; copyLSB set all bits of result to least significant bit of x Example: copyLSB (5) =6xFFFFFFFF, copyLSB (6) =6x00000000 Legal ops:!-&1+ > Max ops: 5 Rating: 2 int copyLSB(int x) t return 2 * evenBits -return word with all even-numbered bits set to 1 Legal ops:!&+ Max ops:8 Rating: 1 void) int evenBits ( return 2; * minusOne- return a value of -1 Legal ops:!&+ Max ops: 2 Rating: 1 1 void) int minusOne ( return 2; copyLSB set all bits of result to least significant bit of x Example: copyLSB (5) =6xFFFFFFFF, copyLSB (6) =6x00000000 Legal ops:!-&1+ > Max ops: 5 Rating: 2 int copyLSB(int x) t return 2

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_2

Step: 3

blur-text-image_3

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

What are the best practices for managing a large software project?

Answered: 1 week ago