Question
C Program exercise I need to help doing this method. It must pass the test I have listed below. While obeying the restrictions. /** *
C Program exercise
I need to help doing this method. It must pass the test I have listed below. While obeying the restrictions.
/** * accepts as input an uint64_t and returns the bits low through * high of the uint64_t. bit 0 is the low order bit and bit 63 * is the high order bit. returns 0 if the low or high bit numbers * are out of range * * for example, getBits(0x8877665544332211, 0, 7) returns 0x11 * getBits(0x8877665544332211, 4, 11) returns 0x21 * getBits(0x8877665544332211, 0, 63) returns 0x8877665544332211 * * @param uint64_t source that holds the bits to be grabbed and * returned * @param int32_t low that is the bit number of the lowest numbered * bit to be returned * @param int32_t high that is the bit number of the highest numbered * bit to be returned * @return an uint64_t that holds a subset of the source bits * that is returned in the low order bits; 0 if low or high * is out of range * * * RESTRICTIONS: You can use an if statement to determine whether * the low and high values are valid. The remaining statements * need to be simple assignment statements. (No loops, switch, * ternary operator , or other conditional statements....) * The purpose of this restriction is to push you to write * "clean" code. */ uint64_t Tools::getBits(uint64_t source, int32_t low, int32_t high) { return 0; }
TEST
/** * tests the getByte method in the Tools class * * getByte takes an uint64_t as input that is the source * and an int32_t containing a byte number in the range 0 to 7. * getByte returns the numbered byte from the source. If the byte number * is out of range, getByte returns 0. * uint64_t Tools::getByte(uint64_t ul, int32_t byteNum); */ void getByteTests() { /* getByte tests */ assert(Tools::getByte(0x8877665544332211, 0) == 0x11); assert(Tools::getByte(0x8877665544332211, 1) == 0x22); assert(Tools::getByte(0x8877665544332211, 2) == 0x33); assert(Tools::getByte(0x8877665544332211, 3) == 0x44); assert(Tools::getByte(0x8877665544332211, 4) == 0x55); assert(Tools::getByte(0x8877665544332211, 5) == 0x66); assert(Tools::getByte(0x8877665544332211, 6) == 0x77); assert(Tools::getByte(0x8877665544332211, 7) == 0x88); assert(Tools::getByte(0x1234567821436587, 0) == 0x87); assert(Tools::getByte(0x1234567821436587, 1) == 0x65); assert(Tools::getByte(0x1234567821436587, 2) == 0x43); assert(Tools::getByte(0x1234567821436587, 3) == 0x21); assert(Tools::getByte(0x1234567821436587, 4) == 0x78); assert(Tools::getByte(0x1234567821436587, 5) == 0x56); assert(Tools::getByte(0x1234567821436587, 6) == 0x34); assert(Tools::getByte(0x1234567821436587, 7) == 0x12); assert(Tools::getByte(0x1234567821436587, 8) == 0x00); assert(Tools::getByte(0x1234567821436587, -1) == 0x00); assert(Tools::getByte(0x1234567821436587, 0x7fffffff) == 0x00); assert(Tools::getByte(0x1234567821436587, 9) == 0x00); assert(Tools::getByte(0x1234567821436587, 10) == 0x00); }
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