Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <cmath>
  4.  
  5. double align_nb(int n) { return { ceil(n / 512.0)*512.0 }; } // bytes
  6. double align_pt(int k) { return { floor(k / 512.0)*512.0 }; } // pointer
  7.  
  8. int main(int argc, char * argv[])
  9. {
  10. int o_n = std::atoi(argv[1]); // original number
  11. int o_p = std::atoi(argv[2]); // original pointer
  12.  
  13. int max_bytes, new_pointer; // max bytes to read, new pointer to point
  14.  
  15.  
  16. float log = (std::log(o_n) / std::log(2));
  17. if (log != floor(log))
  18. {
  19. max_bytes = align_nb(o_n); // bytes alinhados para a frente
  20. new_pointer = align_pt(o_p); // ponteiro alinhado atrás
  21. }
  22.  
  23. else if (log == floor(log))
  24. {
  25. new_pointer = align_pt(o_p);
  26. if (max_bytes + (o_p - new_pointer) >max_bytes)
  27. {
  28. max_bytes += 512;
  29. }
  30. }
  31.  
  32.  
  33. std::cout << "Original bytes= " << o_n << std::endl;
  34. std::cout << "Original pointer= " << o_p << std::endl;
  35. std::cout << "Max_bytes= " << max_bytes << std::endl;
  36. std::cout << "new_pointer= " << new_pointer << std::endl;
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement