Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Each function should perform a series of bitwise operations (usually just one) on an integer, and return the resulting integer. It needs to be done

Each function should perform a series of bitwise operations (usually just one) on an integer, and return the resulting integer. 

It needs to be done using ONLY bitwise operations, except for the following functions where an "if" statement is okay:

  • ifBit7is0
  • ifBit3is1
  • signedBits0through5
  • signedBits6through9

Here is a table showing examples of the output for each function:

Function Input Output
multiplyBy8 7 56
setBit6to1 0x01 0x41
setBit3to0 0xffff 0xfff7
flipBit5 0x01 0x21
ifBit7is0 0x77 nonzero
ifBit3is1 0x77 0
unsignedBits0through5 0x335 0x35
unsignedBits6through9 0x3b4 0xe
signedBits0through5 0x3fa 0xfffffffa
signedBits6through9 0xcf7 0x03
signedBits0through5 0x38f 0xf
signedBits6through9 0x38f 0xfffffffe
setBits4through9 (0xffffffff, 0x23) 0xfffffe3f

The function that needs the most explanation is setBits4through9. Think of this as replacing bits 4-9 (inclusive) with the second input's lowest bits. Leave the rest of the input's bits unchanged.

Any extracted bits should be returned in the lowest bits of the return value. For example, in unsignedBits6through9, if bits 0110 were extracted from the value, then 0110 with 28 leading zeros should be returned (we are working with 32-bit integers).

Here is the .c file that needs to be edited...

#include "stdio.h" #include "stdlib.h" int multiplyBy8(int v) { // TODO: multiply the number by 8 return v; } int setBit6to1(int v) { // TODO: set bit 6 to 1 return v; } int setBit3to0(int v) { // TODO: set bit 3 to 0 return v; } int flipBit5(int v) { // TODO: flip bit 5 (if it is 0, make it 1. If 0, make 1) return v; } int ifBit7is0(int v) { // TODO: check to see if bit 7 is a 0 - return 1 if true, 0 if false return v; } int ifBit3is1(int v) { // check to see if bit 3 is a 1 - return 1 if true, 0 if false return v; } int unsignedBits0through5(int v) { // return the unsigned value in bits 0 through 5 return v; } int unsignedBits6through9(int v) { // return the unsigned value in bits 6 through 9 return v; } int signedBits0through5(int v) { // return the signed value in bits 0 through 5 return v; } int signedBits6through9(int v) { // return the signed value in bits 6 through 9 return v; } int setBits4through9(int v, int setValue) { // set bits 4 through 9 in v to become setValue return v; }

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

Database And Expert Systems Applications Dexa 2022 Workshops 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 In Computer And Information Science 33

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Alfred Taudes ,Atif Mashkoor ,Johannes Sametinger ,Jorge Martinez-Gil ,Florian Sobieczky ,Lukas Fischer ,Rudolf Ramler ,Maqbool Khan ,Gerald Czech

1st Edition

3031143426, 978-3031143427

More Books

Students also viewed these Databases questions

Question

manageremployee relationship deteriorating over time;

Answered: 1 week ago