Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <cmath>
- double align_nb(int n) { return { ceil(n / 512.0)*512.0 }; } // bytes
- double align_pt(int k) { return { floor(k / 512.0)*512.0 }; } // pointer
- int main(int argc, char * argv[])
- {
- int o_n = std::atoi(argv[1]); // original number
- int o_p = std::atoi(argv[2]); // original pointer
- int max_bytes, new_pointer; // max bytes to read, new pointer to point
- float log = (std::log(o_n) / std::log(2));
- if (log != floor(log))
- {
- max_bytes = align_nb(o_n); // bytes alinhados para a frente
- new_pointer = align_pt(o_p); // ponteiro alinhado atrás
- }
- else if (log == floor(log))
- {
- new_pointer = align_pt(o_p);
- if (max_bytes + (o_p - new_pointer) >max_bytes)
- {
- max_bytes += 512;
- }
- }
- std::cout << "Original bytes= " << o_n << std::endl;
- std::cout << "Original pointer= " << o_p << std::endl;
- std::cout << "Max_bytes= " << max_bytes << std::endl;
- std::cout << "new_pointer= " << new_pointer << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement