Starting from:

$19.99

Assignment 4: Write a function int cryptic calculator

Assignment 4
Questions 1. (40points)Writeafunctionint cryptic calculator(void *payload) Where: • If the first byte in payload is a character ’*’ representing the multiplication operation, you are to return the product of 3 short ints starting at bytes 3, 5 and 7. • If the first byte in the payload is a character ’/’ representing division, you are to return the quotient when you divide int starting at byte 5 by short int starting at byte 3. If short int starting at byte 3 is 0, you are to return 0xBAD.
1
• If the first byte is neither ’*’ or ’/’, you are to return 0xBAD. HINT:Castpayloadtoanappropriateappropriatestructure. Byte1isat&payload, byte 3 is at &payload + 2, byte 5 is at &payload + 4 and so on.
2. (40points)Writeafunction: void my memcpy(void *dst, void *src, unsigned int num bytes)thatcopiesnum bytesfrommemorypointed tobysrctomemorypointedtobydst. HINT:Loopnum bytestimesandcopy one char at a time from src to dst.
3. (20 points) Write a function: void swap strs(char *s1, char *s2) that swaps two character strings at s1 and s2. Assume both strings s1 and s2 to be of same length.

More products