Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The source code is below that was provided choose either one of them (c or c++) Thanks! C++ Source - #include #include #include // This

The source code is below that was provided choose either one of them (c or c++)

Thanks!

image text in transcribed

C++ Source -

#include  #include  #include  // This gets me sized types, such as uint32_t using namespace std; /* * The 32 bit data we'll evaluate is broken into five fields as outlined in the * figure below. The top row of numbers identifies the high and low bits in * the fields defined below. The middle row identifies the names of the * fields. The bottom row of numbers identifies how long each bit field is. * * 31 29 28 26 25 12 11 10 0 * +-------+------+----------+-------+-------+ * | Color | Item | Sequence | Taxed | Count | * +-------+------+----------+-------+-------+ * 3 bits 3 bits 14 bits 1 bit 11 bits * * Fields... * - Color: 3 bit values from 0-7. * 0: undefined * 1-7 are the "ROYGBIV" colors of the rainbow * - Item: This 3 bit number should be printed as an unsigned decimal value * - Sequence: This 14 bit value should be printed in binary * - Taxed: a Boolean field where 0 = "False" and 1 = "True" * - Count: This count should be printed as an unsigned decimal value */ /* * Bit field positions */ const unsigned int COLOR_BIT_LOW = 29; const unsigned int COLOR_BIT_HIGH = 31; const unsigned int ITEM_BIT_LOW = 26; const unsigned int ITEM_BIT_HIGH = 28; const unsigned int SEQUENCE_BIT_LOW = 12; const unsigned int SEQUENCE_BIT_HIGH = 25; const unsigned int TAXED_BIT_LOW = 11; const unsigned int TAXED_BIT_HIGH = 11; const unsigned int COUNT_BIT_LOW = 0; const unsigned int COUNT_BIT_HIGH = 10; /* * Bit field lengths calculated from the above positions */ const unsigned int COLOR_BIT_LENGTH = COLOR_BIT_HIGH - COLOR_BIT_LOW + 1; const unsigned int ITEM_BIT_LENGTH = ITEM_BIT_HIGH - ITEM_BIT_LOW + 1; const unsigned int SEQUENCE_BIT_LENGTH = SEQUENCE_BIT_HIGH - SEQUENCE_BIT_LOW + 1; const unsigned int TAXED_BIT_LENGTH = TAXED_BIT_HIGH - TAXED_BIT_LOW + 1; const unsigned int COUNT_BIT_LENGTH = COUNT_BIT_HIGH - COUNT_BIT_LOW + 1; /**************************************************************** **************************************************************** * Bitmask definitions... these are junk... all in hex! * * Replace the inline hex values below with superb bitmasks that utilize the * various constants defined above. This is the ONLY code you should modify. **************************************************************** ****************************************************************/ const uint32_t MASK_COLOR = 0xE0000000; const uint32_t MASK_ITEM = 0x1C000000; const uint32_t MASK_SEQUENCE = 0x3FFF000; const uint32_t MASK_TAXED = 0x800; const uint32_t MASK_COUNT = 0x7FF; void print_color(uint32_t bp); void print_item(uint32_t bp); void print_sequence(uint32_t bp); void print_taxed(uint32_t bp); void print_count(uint32_t bp); int main(int argc, char *argv[]) { const int SIZE = 15; uint32_t bit_patterns[SIZE] = { 0x35df9869, 0xb761dcff, 0xff81f29, 0xbc23d7ab, 0x769f29e3, 0x5bee62c2, 0x91ea231b, 0x1cc3a82d, 0x8231f92e, 0xbaf6579f, 0xda7fb665, 0x6b1d57b7, 0x975d30a3, 0xd21e095d, 0xb5c82858 }; for(int i = 0; i > COLOR_BIT_LOW]; return; } void print_item(uint32_t bp) { cout > ITEM_BIT_LOW); return; } void print_sequence(uint32_t bp) { cout = SEQUENCE_BIT_LOW); return; } void print_taxed(uint32_t bp) { cout > COUNT_BIT_LOW); return; }

C Source below -

#include  #include  #include  // This gets me sized types, such as uint32_t /* * The 32 bit data we'll evaluate is broken into five fields as outlined in the * figure below. The top row of numbers identifies the high and low bits in * the fields defined below. The middle row identifies the names of the * fields. The bottom row of numbers identifies how long each bit field is. * * 31 29 28 26 25 12 11 10 0 * +-------+------+----------+-------+-------+ * | Color | Item | Sequence | Taxed | Count | * +-------+------+----------+-------+-------+ * 3 bits 3 bits 14 bits 1 bit 11 bits * * Fields... * - Color: 3 bit values from 0-7. * 0: undefined * 1-7 are the "ROYGBIV" colors of the rainbow * - Item: This 3 bit number should be printed as an unsigned decimal value * - Sequence: This 14 bit value should be printed in binary * - Taxed: a Boolean field where 0 = "False" and 1 = "True" * - Count: This count should be printed as an unsigned decimal value */ /* * Bit field positions */ const unsigned int COLOR_BIT_LOW = 29; const unsigned int COLOR_BIT_HIGH = 31; const unsigned int ITEM_BIT_LOW = 26; const unsigned int ITEM_BIT_HIGH = 28; const unsigned int SEQUENCE_BIT_LOW = 12; const unsigned int SEQUENCE_BIT_HIGH = 25; const unsigned int TAXED_BIT_LOW = 11; const unsigned int TAXED_BIT_HIGH = 11; const unsigned int COUNT_BIT_LOW = 0; const unsigned int COUNT_BIT_HIGH = 10; /* * Bit field lengths calculated from the above positions */ const unsigned int COLOR_BIT_LENGTH = COLOR_BIT_HIGH - COLOR_BIT_LOW + 1; const unsigned int ITEM_BIT_LENGTH = ITEM_BIT_HIGH - ITEM_BIT_LOW + 1; const unsigned int SEQUENCE_BIT_LENGTH = SEQUENCE_BIT_HIGH - SEQUENCE_BIT_LOW + 1; const unsigned int TAXED_BIT_LENGTH = TAXED_BIT_HIGH - TAXED_BIT_LOW + 1; const unsigned int COUNT_BIT_LENGTH = COUNT_BIT_HIGH - COUNT_BIT_LOW + 1; /**************************************************************** **************************************************************** * Bitmask definitions... these are junk... all in hex! * * Replace the inline hex values below with superb bitmasks that utilize the * various constants defined above. This is the ONLY code you should modify. **************************************************************** ****************************************************************/ const uint32_t MASK_COLOR = 0xE0000000; const uint32_t MASK_ITEM = 0x1C000000; const uint32_t MASK_SEQUENCE = 0x3FFF000; const uint32_t MASK_TAXED = 0x800; const uint32_t MASK_COUNT = 0x7FF; void print_color(uint32_t bp); void print_item(uint32_t bp); void print_sequence(uint32_t bp); void print_taxed(uint32_t bp); void print_count(uint32_t bp); int main(int argc, char *argv[]) { uint32_t bit_patterns[] = { 0x35df9869, 0xb761dcff, 0xff81f29, 0xbc23d7ab, 0x769f29e3, 0x5bee62c2, 0x91ea231b, 0x1cc3a82d, 0x8231f92e, 0xbaf6579f, 0xda7fb665, 0x6b1d57b7, 0x975d30a3, 0xd21e095d, 0xb5c82858 }; const int SIZE = sizeof(bit_patterns) / sizeof(bit_patterns[0]); for(int i = 0; i > COLOR_BIT_LOW]); return; } void print_item(uint32_t bp) { printf("Item = %d", (bp & MASK_ITEM) >> ITEM_BIT_LOW); return; } void print_sequence(uint32_t bp) { printf("Sequence = "); int i = SEQUENCE_BIT_HIGH; do { printf("%d", bp & (1 = SEQUENCE_BIT_LOW); return; } void print_taxed(uint32_t bp) { printf("Taxed = %s", (bp & MASK_TAXED) ? "True" : "False"); return; } void print_count(uint32_t bp) { printf("Count = %d", (bp & MASK_COUNT) >> COUNT_BIT_LOW); return; }
Prog2: Using Superb Bitmasks (CS220-02, 05) Given the source code for a working bitmask program written by the professor (choose either the C or C++ source), modify only the section of code that defines the set of 5 bit masks. Modify them from their terrible hex selves to use superb bitmasks based on the constants defined above that. For each field identified in the bit field layout comments of the program, there are ....LOW, ...HIGH, and ...LENGTH constants that identify the low bit position of the field, the high bit position of the field, and the length of the field in bits. Your modified program should not result in any change in output at all from the original program. Prog2: Using Superb Bitmasks (CS220-02, 05) Given the source code for a working bitmask program written by the professor (choose either the C or C++ source), modify only the section of code that defines the set of 5 bit masks. Modify them from their terrible hex selves to use superb bitmasks based on the constants defined above that. For each field identified in the bit field layout comments of the program, there are ....LOW, ...HIGH, and ...LENGTH constants that identify the low bit position of the field, the high bit position of the field, and the length of the field in bits. Your modified program should not result in any change in output at all from the original program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago