Question: Write a function that extracts a number of fields of different sizes from an integer type. You have to extract 10 fields of given widths,

Write a function that extracts a number of fields of different sizes from an integer type. You have to extract 10 fields of given widths, from left to right (most significant to least significant) from a 32-bit int of a given value.

The field widths, in bits, are:

3, 4, 4, 3, 3, 4, 4, 3, 2, and 2.

If we use lower case letters a through j for the bits of the fields, in order, then the 32-bit value looks like this:

aaabbbbccccdddeeeffffgggghhhiijj

The specific value from which you are to extract the 10 fields is: 0xCAFEBABE. You are to extract each field using only the << and >> operators of C. Print the (unsigned) values of the 10 fields, from left to right, separated by spaces (by using a printf format such as "%d %d ... %d ".

First initialize a new variable to the value 0xCAFEBABE and then extract the fields into 10 separate variables. Finally, print the values of those variables, left to right.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!