Question

Write a C function that declares a static integer array, M, and implements fetch and store...

Write a C function that declares a static integer array, M, and implements fetch and store operations that use shift and Boolean operations to access individual bytes.

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

C program for accessing and storing static integer byte by byte:

======================

#include<stdio.h>
static int arr[5]={0xabcd,2,3,4,5};
void main(){
int *p=&arr;
int mask=0x000f;
printf("Accessing arr[0] byte by byte:\n");
printf("mask byte\n");
printf("%x ",mask);
printf("%x\n",(*p)&mask);
mask=mask<<4; // mask= 0x00f0 for accessing LSByte
printf("%x ",mask);
printf("%x\n",((*p)&mask)>>4);
mask=mask<<4; // mask= 0x0f00
printf("%x ",mask);
printf("%x\n",((*p)&mask)>>8);
mask=mask<<4; // mask= 0xf000 for accessing MSByte
printf("%x ",mask);
printf("%x\n",((*p)&mask)>>12);

printf("array element at arr[%d]: %x\n",0,arr[0]);
int dataByte=0xe;
*p=(*p)|(dataByte<<4); // for storing data byte at location 3 in first element of arrray
printf("aftering storing data byte arr[%d]= %x\n",0,arr[0]);

}


===========================

Add a comment
Know the answer?
Add Answer to:
Write a C function that declares a static integer array, M, and implements fetch and store...
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
  • Write code that declares an array of integer values that will represent the first five even...

    Write code that declares an array of integer values that will represent the first five even numbers: 2, 4, 6, 8, 10. Add code to initialize each element of the array with the even number values shown above. Add code to calculate the product of the array elements, and store the result in a variable named product. You must access the array elements to accomplish this. Do not write product = 2 * 4 * 6 * 8 * 10;...

  • In C: Write a function "MinMax" that takes as an argument an integer array, an integer...

    In C: Write a function "MinMax" that takes as an argument an integer array, an integer for the size of the array, and two integer pointers. The function should print nothing and return nothing but change the value of the first pointer to the minimum value in the array and change the value in the second pointer to the max value in the array.

  • Structures in C++ :- 2. Write a program that declares a structure to store the distance...

    Structures in C++ :- 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then display the record of the winner. 3. Write a program that declares a structure to store income, tax rate and tax of a person. The program defines an array of structure to store the records of five person. It inputs income...

  • Structures in C++ :- 1. Write a program that declares a structure to store the code...

    Structures in C++ :- 1. Write a program that declares a structure to store the code number, salary and grade of an employee. The program defines two structure variables, inputs record of two employees and then displays the record of the employee with more salary. 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then...

  • Write a program that meets the following criteria: Define a function that implements the selection sort...

    Write a program that meets the following criteria: Define a function that implements the selection sort algorithm to sort an integer array. Define a function that implements the binary search algorithm to search an array for a given integer. The function must return the location of the integer if it is found or a -1 if it is not found. The main function in your program must declare an integer array initialized with 10 unsorted values. The main function must...

  • Submit two C++ files: 1. Write a C++ program that declares an array alpha of 50...

    Submit two C++ files: 1. Write a C++ program that declares an array alpha of 50 components of type double. Initialize the array so that the first 25 components are equal to the square of the index variable, and the last 25 components are equal to three times the index variable. Output the array so that 10 elements per line are printed. 2. Write a program that prompts the user to input a string and outputs the string in uppercase...

  • iostream and basic function only plz Write a c++ program which declares an array which can...

    iostream and basic function only plz Write a c++ program which declares an array which can hold 50 int values. Use a const to establish the size of the array. Use a loop to fill the array with 50 random numbers. Then display the values 10 per line, like: 32734  11377 29730 25790 27662 31264   5530   7441 14377  21719 28059  27864   4276   1495 29687 12784 19497 31106 21525 22643

  • In C++ Write a function that receives an integer array with its size and determines whether...

    In C++ Write a function that receives an integer array with its size and determines whether the array is already sorted in increasing order. Write a test program (main function) that prompts the use to enter a list and displays whether the list is sorted or not. The first number in the input indicates the size of the list. Assume the maximum list size is 20.

  • In C++ Write a function that receives an integer array with its size and determines whether...

    In C++ Write a function that receives an integer array with its size and determines whether the array is already sorted in increasing order. Write a test program (main function) that prompts the use to enter a list and displays whether the list is sorted or not. The first number in the input indicates the size of the list. Assume the maximum list size is 20.

  • 3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and pr...

    3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Your program must, at least, contain a function to read and store a number into an...

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