Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. uint32_t f(uint32_t x)
  2. {
  3. int n = highest_set(x);
  4. for (int i = 31; i != n; --i) {
  5. x |= 1 << i;
  6. }
  7. return x;
  8. }
  9.  
  10. uint32_t f(uint32_t x)
  11. {
  12. bool bitset=false; //C++
  13. for (int i =0; i<sizeof(int); i++) {
  14. if(bitset) //After the first 1
  15. { x |= 1 << i; }
  16. else
  17. {
  18. if(x&(1<<i))
  19. bitset=true; //if 1 found then the flag is raised
  20. }
  21.  
  22. }
  23. return x;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement