Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. Warm up exercises:
  2. 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.
  3. The function will iterate over the unsigned input and print out all the Nibbles in the order determined by the direction input.
  4. If direction equals 0, print from lowest Nibble to highest Nibble (right to left).
  5. If direction is different than 0, print from highest Nibble to lowest Nibble (left to right).
  6.  
  7. 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.
  8. Examples:
  9. Input: 0x12345678 Output: 0x15, 0x26, 0x37, 0x48
  10. Input: 0xABCD0000 Output: 0xA0, 0xB0, 0xC0, 0xD0
  11. Input: 0x00004567 Output: 0x4, 0x5, 0x6, 0x7
  12. Input: 0x12121212 Output: 0x11, 0x22, 0x11, 0x22
  13.  
  14. 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.
  15. 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.
  16.  
  17. P4: Write a function that takes an unsigned as an input and does the following operations, then returns the result:
  18. - if a bit is set on an even position (start counting from 0 for the first bit), swap it
  19. - if a bit is set on an odd position, clear it
  20. 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.
  21.  
  22. P5: Write a function that given an unsigned n returns the number of segments of consecutive equal bits in the binary representation of n.
  23. Example: 000100 has three segments: 000, 1, 00, so it returns 3.
  24. 01010101 returns 8
  25. 00000000 returns 1
  26. 00010100 returns 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement