BitFunctions.inc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /****************************************************************************************************
  2. * *
  3. * )( Bit Functions )( *
  4. * *
  5. * Copyright © 2017 Abyss Morgan. All rights reserved. *
  6. * *
  7. * Download: https://github.com/AbyssMorgan/SA-MP/tree/master/include/SAM *
  8. * Publication: http://forum.sa-mp.com/showthread.php?t=591223 *
  9. * Website: http://8.ct8.pl *
  10. * *
  11. * Plugins: None *
  12. * Modules: None *
  13. * *
  14. * File Version: 1.8.0 *
  15. * SA:MP Version: 0.3.7 *
  16. * *
  17. * bit 0 - 31: *
  18. * (bit 31) --> 11111111000000001111010001010000 <-- (bit 0) *
  19. * *
  20. * Example cell mode: *
  21. * Mode 2 (cell id 15) --> 11 11 11 11 00 00 00 00 11 11 01 00 01 01 00 00 <-- (cell id 0) *
  22. * Mode 4 (cell id 7) --> 1111 1111 0000 0000 1111 0100 0101 0000 <-- (cell id 0) *
  23. * Mode 8 (cell id 3) --> 11111111 00000000 11110100 01010000 <-- (cell id 0) *
  24. * Mode 16 (cell id 1) --> 1111111100000000 1111010001010000 <-- (cell id 0) *
  25. * *
  26. * General Macros: *
  27. * GetValueBit(value,bit); *
  28. * SetValueBit(&value,bit,power); //power 0 or 1 *
  29. * SetValueBitTrue(&value,bit); *
  30. * SetValueBitFalse(&value,bit); *
  31. * GetCellValue(value,cellid,mode); *
  32. * SetCellValue(&value,cellid,mode,power); *
  33. * GetCellValueEx(value,offset,cellsize); *
  34. * SetCellValueEx(&value,offset,cellsize,power); *
  35. * InvertValue(value); *
  36. * InvertValueEx(value,key); //default key 0xFFFFFFFF *
  37. * bool:CheckValue(value,&count=0); //even - false,uneven - true *
  38. * *
  39. * File Byte Macros: *
  40. * ExtractValue(value,&byte1,&byte2,&byte3,&byte4); *
  41. * ExtractFloat(Float:value,&byte1,&byte2,&byte3,&byte4); *
  42. * MergeValue(&value,byte1,byte2,byte3,byte4); *
  43. * MergeFloat(&Float:value,byte1,byte2,byte3,byte4); *
  44. * MergeValueEx(byte1,byte2,byte3,byte4); *
  45. * Float:MergeFloatEx(byte1,byte2,byte3,byte4); *
  46. * *
  47. * Dynamic Toggle Config Macros: *
  48. * GetConfigAddress(itemid); *
  49. * GetConfigBit(itemid); *
  50. * GetConfigSize(max_items); *
  51. * IsToggleConfigInformation(variable,itemid); *
  52. * ToggleConfigInformation(variable,itemid,value); //values: 1/0 *
  53. * *
  54. ****************************************************************************************************/
  55. /*
  56. //Check Version BitFunctions.inc
  57. #if !defined __bit_function
  58. #error [ADM] You need BitFunctions.inc v1.8.0
  59. #elseif !defined BitFunction_Version
  60. #error [ADM] Update you BitFunctions.inc to v1.8.0
  61. #elseif (BitFunction_Version < 10800)
  62. #error [ADM] Update you BitFunctions.inc to v1.8.0
  63. #endif
  64. */
  65. #if defined _bit_function
  66. #endinput
  67. #endif
  68. #define _bit_function
  69. #define BitFunction_Version (10800) //a.b.c 10000*a+100*b+c
  70. //General Macros
  71. #define GetValueBit(%0,%1) ((%0) >>> (%1) & 0x01)
  72. #define SetValueBit(%0,%1,%2) ((%0) = (((%0) & ~(0x01 << (%1))) | ((0x01 << (%1))*(%2))))
  73. #define SetValueBitTrue(%0,%1) ((%0) |= (0x01 << (%1)))
  74. #define SetValueBitFalse(%0,%1) ((%0) &= ~(0x01 << (%1)))
  75. #define InvertValue(%0) ((%0) ^ 0xFFFFFFFF)
  76. #define InvertValueEx(%0,%1) ((%0) ^ (%1))
  77. #define SetCellValue(%0,%1,%2,%3) ((%0) = (((%0) & ~((((0x01 << (%2))-1) << (%1)*(%2)))) | ((%3) << (%1)*(%2))))
  78. #define GetCellValue(%0,%1,%2) (((%0) & (((0x01 << (%2))-1) << (%1)*(%2))) >>> ((%1)*(%2)))
  79. #define SetCellValueEx(%0,%1,%2,%3) ((%0) = (((%0) & ~((((0x01 << (%2))-1) << (%1)))) | ((%3) << (%1))))
  80. #define GetCellValueEx(%0,%1,%2) (((%0) & (((0x01 << (%2))-1) << (%1))) >>> (%1))
  81. //File Byte Macros
  82. #define ExtractValue(%0,%1,%2,%3,%4) ((%1) = (((%0) & 0xFF000000) >>> 24),(%2) = (((%0) & 0x00FF0000) >>> 16),(%3) = (((%0) & 0x0000FF00) >>> 8),(%4) = ((%0) & 0x000000FF))
  83. #define ExtractFloat(%0,%1,%2,%3,%4) ((%1) = (((_:%0) & 0xFF000000) >>> 24),(%2) = (((_:%0) & 0x00FF0000) >>> 16),(%3) = (((_:%0) & 0x0000FF00) >>> 8),(%4) = ((_:%0) & 0x000000FF))
  84. #define MergeValue(%0,%1,%2,%3,%4) ((%0) = (((%1) << 24) | ((%2) << 16) | ((%3) << 8) | (%4)))
  85. #define MergeFloat(%0,%1,%2,%3,%4) ((%0) = Float:(((%1) << 24) | ((%2) << 16) | ((%3) << 8) | (%4)))
  86. #define MergeValueEx(%1,%2,%3,%4) (((%1) << 24) | ((%2) << 16) | ((%3) << 8) | (%4))
  87. #define MergeFloatEx(%1,%2,%3,%4) (Float:(((%1) << 24) | ((%2) << 16) | ((%3) << 8) | (%4)))
  88. //Dynamic Toggle Config Macros
  89. #define GetConfigAddress(%0) (floatround((%0)/32))
  90. #define GetConfigBit(%0) ((%0) % 32)
  91. #define GetConfigSize(%0) (((%0) / 32)+1)
  92. #define IsToggleConfigInformation(%0,%1) GetValueBit(%0[GetConfigAddress(%1)],GetConfigBit(%1))
  93. #define ToggleConfigInformation(%0,%1,%2) SetValueBit(%0[GetConfigAddress(%1)],GetConfigBit(%1),((%2) & 0x1))
  94. stock bool:CheckValue(value,&count=0){
  95. new int = 0;
  96. for(new i = 31; i >= 0; i--){
  97. if(GetValueBit(value,i)){
  98. int++;
  99. }
  100. }
  101. count = int;
  102. if(int % 2 == 0) return false;
  103. return true;
  104. }
  105. //EOF