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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started