Advertisement
Guest User

Untitled

a guest
Dec 21st, 2011
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     SA-MP "rBits" Include
  3.     Copyright © 2011 RyDeR`
  4. */
  5.  
  6. #if defined _Included_rBits
  7.     #endinput
  8. #endif
  9.  
  10. #define _Included_rBits
  11.  
  12. #define BIT_TAGS \
  13.     { Bit1, Bit2, Bit4, Bit8, Bit16 }
  14.    
  15. enum e_Bits
  16. {
  17.     Bit1,
  18.     Bit2,
  19.     Bit4,
  20.     Bit8,
  21.     Bit16,
  22.     Bit32
  23. };
  24.  
  25. #define Bit1:%0<%1> \
  26.     Bit1: %0[((%1) + 31) >>> _: Bit32]
  27.    
  28. #define Bit1_Set(%0,%1,%2) \
  29.     Bit_Set(%0, (%1), (%2), Bit1)
  30.    
  31. #define Bit1_Get(%0,%1) \
  32.     Bit_Get(%0, (%1), Bit1)
  33.  
  34. #define Bit2:%0<%1> \
  35.     Bit2: %0[((%1) + 15) >>> _: (Bit32 - Bit2)]
  36.    
  37. #define Bit2_Set(%0,%1,%2) \
  38.     Bit_Set(%0, (%1), (%2), Bit2)
  39.    
  40. #define Bit2_Get(%0,%1) \
  41.     Bit_Get(%0, (%1), Bit2)
  42.  
  43. #define Bit4:%0<%1> \
  44.     Bit4: %0[((%1) + 7) >>> _: (Bit32 - Bit4)]
  45.    
  46. #define Bit4_Set(%0,%1,%2) \
  47.     Bit_Set(%0, (%1), (%2), Bit4)
  48.    
  49. #define Bit4_Get(%0,%1) \
  50.     Bit_Get(%0, (%1), Bit4)
  51.  
  52. #define Bit8:%0<%1> \
  53.     Bit8: %0[(%1) char]
  54.    
  55. #define Bit8_Set(%0,%1,%2) \
  56.     (_: %0{(%1)} = (%2))
  57.    
  58. #define Bit8_Get(%0,%1) \
  59.     (_: %0{(%1)})
  60.  
  61. #define Bit16:%0<%1> \
  62.     Bit16: %0[((%1) + 1) >>> _: (Bit32 - Bit16)]
  63.    
  64. #define Bit16_Set(%0,%1,%2) \
  65.     Bit_Set(%0, (%1), (%2), Bit16)
  66.    
  67. #define Bit16_Get(%0,%1) \
  68.     Bit_Get(%0, (%1), Bit16)
  69.    
  70. stock Bit_Set(BIT_TAGS: bitArr[], arrIdx, value, e_Bits: bitShift, arrSize = sizeof(bitArr))
  71. {
  72.     new
  73.         bitVar = ((arrIdx & ((1 << _: (Bit32 - bitShift)) - 1)) << _: bitShift),
  74.         bitLim = ((1 << (1 << _: bitShift)) - 1)
  75.     ;
  76.     if(!(0 <= (arrIdx >>>= _: (Bit32 - bitShift)) < arrSize))
  77.         return 0;
  78.    
  79.     (_: bitArr[arrIdx]) &= ~(bitLim << bitVar);
  80.     (_: bitArr[arrIdx]) |= ((bitLim & value) << bitVar);
  81.    
  82.     return 1;
  83. }
  84.  
  85. stock Bit_Get(BIT_TAGS: bitArr[], arrIdx, e_Bits: bitShift, arrSize = sizeof(bitArr))
  86. {
  87.     new
  88.         bitVar = ((arrIdx & ((1 << _: (Bit32 - bitShift)) - 1)) << _: bitShift),
  89.         bitLim = ((1 << (1 << _: bitShift)) - 1)
  90.     ;
  91.     if(!(0 <= (arrIdx >>>= _: (Bit32 - bitShift)) < arrSize))
  92.         return 0;
  93.    
  94.     return ((_: bitArr[arrIdx] >>> bitVar) & bitLim);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement