-1

I need to implement but I am not sure how can I as I am completely new into this. A function called get_values that has the prototype:

void get_values(unsigned int value, unsigned int *p_lsb, unsigned int *p_msb, 
                unsigned int *p_combined) 

The function computes the least significant byte and the most significant byte of the value parameter. In addition, both values are combined. For this problem:

a. You may not use any loop constructs. b. You may not use the multiplication operator (* or *=). c. Your code must work for unsigned integers of any size (4 bytes, 8 bytes, etc.). d. To combine the values, append the least significant byte to the most significant one. e. Your implementation should be efficient.

The following driver (and associated output) provides an example of using the function you are expected to write. Notice that in this example an unsigned int is 4 bytes, but your function needs to work with an unsigned int of any size.

Driver 

int main() { 
   unsigned int value = 0xabcdfaec, lsb, msb, combined; 
   get_values(value, &lsb, &msb, &combined); 
   printf("Value: %x, lsb: %x, msb: %x, combined: %x\n", value, lsb, msb, combined); 

 return 0; 
} 


Output 

Value: abcdfaec, lsb: ec, msb: ab, combined: abec 
ivesingh
  • 31
  • 1
  • 2
  • 3
  • You forgot to ask a question. What is your question about your assignment? – David Schwartz Oct 09 '13 at 02:07
  • I don't think it makes sense. Isn't 'int' defined as 32 bits? How do you tell how many bits it is? Are you assuming it could be 64 bits, and would `0xabcdef` produce `ab` as the most significant byte even though it is bits 16-23 instead of 24-31? – Jason Goemaat Oct 09 '13 at 02:09

1 Answers1

0

I think you want to look into bitwise and and bit shifting operators. The last piece of the puzzle might be the sizeof() operator if the question is asking that the code should work with platforms with different sized int types.

Jason Goemaat
  • 28,692
  • 15
  • 86
  • 113