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.
/** * builds a 64-bit long out of an array of 8 bytes * * for example, suppose bytes[0] == 0x12 * and bytes[1] == 0x34 * and bytes[2] == 0x56 * and bytes[3] == 0x78 * and bytes[4] == 0x9a * and bytes[5] == 0xbc * and bytes[6] == 0xde * and bytes[7] == 0xf0 * then buildLong(bytes) returns 0xf0debc9a78563412 * * @param array of 8 bytes * @return uint64_t where the low order byte is bytes[0] and * the high order byte is bytes[7] */ uint64_t Tools::buildLong(uint8_t bytes[LONGSIZE]) { return 0; } TEST
void buildLongTests() { uint8_t bytes1[LONGSIZE] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; assert(Tools::buildLong(bytes1) == 0x8877665544332211); uint8_t bytes2[LONGSIZE] = {0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11}; assert(Tools::buildLong(bytes2) == 0x1122334455667788); uint8_t bytes3[LONGSIZE] = {0x78, 0x67, 0x56, 0x45, 0x34, 0x23, 0x12, 0x01}; assert(Tools::buildLong(bytes3) == 0x0112233445566778); uint8_t bytes4[LONGSIZE] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01}; assert(Tools::buildLong(bytes4) == 0x0102030405060708); uint8_t bytes5[LONGSIZE] = {0x80, 0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10}; assert(Tools::buildLong(bytes5) == 0x1020304050607080); uint8_t bytes6[LONGSIZE] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff}; assert(Tools::buildLong(bytes6) == 0xffffffff00000000); uint8_t bytes7[LONGSIZE] = {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00}; assert(Tools::buildLong(bytes7) == 0x00000000ffffffff); } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
