Question

Develop in C language the function whose prototype is described below. Please, send the entire code,...

Develop in C language the function whose prototype is described below. Please, send the entire code, including any variable defined before the function, for example.

/ **
@brief Read bit of memory position pointed to by p
@param p Pointer to 32bit variable whose bit will be read
@param bitn Bit position (0 to 31) to be read
@return returns the state (0 or 1) of the memory location bit pointed to by p
* /
unsigned char ReadBit (unsigned long * p, unsigned char bitn) {}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

We know the Bit Numbering starts from 0, So to check if the first bit is set for number 2 i.e 0010 ..Its 1st bit is set, so we should get 1. Here is the Test code as well.





unsigned char ReadBit (unsigned long * p, unsigned char bitn) {

return ((*p) >> bitn) & 1;

}

==============================================================
Full Code

#include <stdio.h>

unsigned char ReadBit (unsigned long * p, unsigned char bitn) {

return ((*p) >> bitn) & 1;

}

int main() {

unsigned long p = 2;

unsigned long *r = &p;

char bitn = 1;

printf("%d\n", ReadBit(r,bitn));

}


=================================================
SEE OUTPUT


PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
Develop in C language the function whose prototype is described below. Please, send the entire code,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 1: Pointers You are given the following C code and memory diagram. The “contents” column...

    Question 1: Pointers You are given the following C code and memory diagram. The “contents” column of the memory diagram shows the value of the variable. Update the “contents” column of the memory diagram for each assignment in main(). long *pt; long data;    long buffer[4]; void main(void){   pt = &buffer[1];   *pt = 1234;   data = *pt; } address      contents   variable 0x20000000 0x00000000    pt 0x20000004 0x00000000    data 0x20000008 0x00000000    buffer[0] 0x2000000C 0x00000000    buffer[1] 0x20000010 0x00000000    buffer[2] 0x20000014 0x00000000    buffer[3]...

  • Using C++ language, write a code to implement the "evaluate function" described below using the given...

    Using C++ language, write a code to implement the "evaluate function" described below using the given poly.cpp file and poly.h header file. (ignore the other 3 functions if asked) poly.cpp file: poly.h header file: You are asked to implement four functions for a data structure used to store polynomials. The data structure used for polynomials is a linked list that consists of terms where each term consists of a coefficient, an exponent and a pointer to the next term. A...

  • Please slove all these questions in C language Write a function insert At Position N ()...

    Please slove all these questions in C language Write a function insert At Position N () for a singly-linked list that has the following declaration and precondition: int insert At Position N (strict node **p Head, int n, int new Data); Precondition: n > 0 and the list always has enough nodes to satisfy the position specified by n. The function should allocate memory for a new node, and initialize it with the new Data value. It should then insert...

  • Do this using the C language. show me the code being executed and also copy and...

    Do this using the C language. show me the code being executed and also copy and paste the code so i can try it out for myseld Instructions A cipher is mirrored algorithm that allow phrases or messages to be obfuscated (ie. "scrambled"). Ciphers were an early form of security used to send hidden messages from one party to another. The most famous and classic example of a cipher is the Caesar Cipher. This cypher worked by shifting each letter...

  • You shall develop a grammar and implement a parser which recognizes valid statements as described below in the assignment specification. You may develop your code using C, C++. The test file include...

    You shall develop a grammar and implement a parser which recognizes valid statements as described below in the assignment specification. You may develop your code using C, C++. The test file include these expressions below. The first six should pass and the rest should fail: first = one1 + two2 - three3 / four4 ; second = one1 * (two2 * three3) ; second = one1 * (two2 * three3) ; third = ONE + twenty - three3 ; third...

  • In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits&gt...

    In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits> #include <iostream> #include <string> // atoi #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ const unsigned int DEFAULT_SIZE = 179; // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() {...

  • A. File I/O using C library functions File I/O in C is achieved using a file...

    A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...

  • Can you please write the two C++ modules below is a step by step instuctions to...

    Can you please write the two C++ modules below is a step by step instuctions to follow that will make it very easy thanks. Create a module called pqueue.cpp that implements priority queues, with a header file calledpqueue.hthat describes what pqueue.cpp exports. The interface includes the following, and nothing else. Types ItemType and PriorityType are discussed below under the refinement plan. A type, PriorityQueue. Creating a PriorityQueue object with line PriorityQueue q; makes q be an initially empty priority queue....

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • Please I need help in C language, I am trying to modify the code per the...

    Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions:                  1.      First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT