Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Warm up exercises:
- P1. Write a function that takes an unsigned as the first input and a "char direction" as a secondary input to control the iteration direction.
- The function will iterate over the unsigned input and print out all the Nibbles in the order determined by the direction input.
- If direction equals 0, print from lowest Nibble to highest Nibble (right to left).
- If direction is different than 0, print from highest Nibble to lowest Nibble (left to right).
- P2. Write a function that takes an unsigned as an input (32 bit unsigned variable) and prints out 4 unsigned char values (8 bit unsigned values) in hex, made using Nibbles 0 & 4, Nibbles 1 & 5, 2 & 6, 3 & 7.
- Examples:
- Input: 0x12345678 Output: 0x15, 0x26, 0x37, 0x48
- Input: 0xABCD0000 Output: 0xA0, 0xB0, 0xC0, 0xD0
- Input: 0x00004567 Output: 0x4, 0x5, 0x6, 0x7
- Input: 0x12121212 Output: 0x11, 0x22, 0x11, 0x22
- P3: Write a function that takes an unsigned as an input and returns the number of bits that are set (equal to 1) in the input.
- Write several tests in your main function and print the returned values in the form of "Input: 0xHHHHHHHH has DD bits set", where H represent hex digits and D represent decimal digits.
- P4: Write a function that takes an unsigned as an input and does the following operations, then returns the result:
- - if a bit is set on an even position (start counting from 0 for the first bit), swap it
- - if a bit is set on an odd position, clear it
- Write several tests in your main function and print the returned values in the form of "Input: 0xHHHHHHHH Output: 0xHHHHHHHH", where H represent hex digits.
- P5: Write a function that given an unsigned n returns the number of segments of consecutive equal bits in the binary representation of n.
- Example: 000100 has three segments: 000, 1, 00, so it returns 3.
- 01010101 returns 8
- 00000000 returns 1
- 00010100 returns 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement