danilom

passa bits

Sep 8th, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void dtob(unsigned int n);
  4.  
  5. int main(void) {
  6.         dtob(456);
  7.         dtob(14);
  8.         dtob(passabits(456, 4, 3, 14);
  9.  
  10.         return 0;
  11. }
  12.  
  13. int passabits(x, p, n, y) unsigned int x, p, n, y; {    
  14.         return x&~(~0u<<32-n>>32-p)|(y&~(~0<<n))<<p-n;
  15. }
  16.  
  17. void dtob(unsigned int n) {
  18.         char i=0;
  19.         do{putchar((n>>31&1)+'0');}while((n<<=1)|++i<32);
  20.         putchar(10);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment