Advertisement
Guest User

some little header

a guest
Nov 17th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | Pets | 0 0
  1. /*
  2.  * bits.h
  3.  *
  4.  *  Created on: 28 июл. 2023 г.
  5.  *      Author:
  6.  */
  7.  
  8. #ifndef BITS_H_
  9. #define BITS_H_
  10.  
  11. //def types
  12. #ifndef bool
  13. typedef _Bool bool;
  14. #endif
  15. #ifndef lint
  16. typedef long long lint;
  17. #endif
  18. #ifndef uint
  19. typedef unsigned int uint;
  20. #endif
  21. #ifndef uchar
  22. typedef unsigned char uchar;
  23. #endif
  24.  
  25. //def macros
  26. #ifndef _nt_setbit
  27. #define _nt_setbit(n,bitn,bit)  \
  28.   {uint pwrd = (powi(2,bitn));if(_nt_getbit(*n,bitn) != bit)\
  29.   *n += ((*n & pwrd) >> bitn) ? (-1 * pwrd) : (pwrd);}
  30. #endif
  31. #ifndef _nt_getbit
  32. #define _nt_getbit(n,bitn)  ((n & (powi(2,bitn))) >> bitn)
  33. #endif
  34.  
  35. //def prots
  36. uint    powi    (uchar, uchar);
  37. bool    getbit  (lint, uchar);
  38. void    setbit  (lint *, uchar, bool);
  39.  
  40. uint powi(uchar num, uchar deg){
  41.   if (!deg)
  42.       return (uint)1;
  43.   if (deg & 1)
  44.       return powi(num, deg - 1) * num;
  45.   num = powi(num, deg >> 1);
  46.   return num * num;
  47. }
  48.  
  49. bool getbit(lint num, uchar b){
  50.   uint pwrd = powi(2,b);
  51.   return (num & pwrd) >> b;
  52. }
  53.  
  54. void setbit(lint * num, uchar b, bool exp){
  55.   uint pwrd = (powi(2,b));
  56.   if(getbit(*num,b) == exp) return;
  57.   *num += ((*num & pwrd) >> b) ? (-1 * pwrd) : (pwrd);
  58. }
  59.  
  60. #endif /* BITS_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement