Advertisement
DraKiNs

[COD] Manipular Alocação BITS

Aug 28th, 2011
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.95 KB | None | 0 0
  1. #define BitVar:%0<%1>               %0[(((%1) + cellbits) / cellbits)]
  2.  
  3.  
  4.  
  5. main()
  6. {
  7.  
  8.     new BitVar:gPlayerData<16>;
  9.  
  10.     setArrayBit(gPlayerData, 4, true);
  11.     setArrayBit(gPlayerData, 2, false);
  12.  
  13.     new semBit[16];
  14.    
  15.     semBit[4] = _:true;
  16.     semBit[2] = _:false;
  17.    
  18.     return printf("\n-----------------------------------------------------------------------------\n\n\t [TESTANDO BITS]  \n  (alocação padrão %d) (alocação manipulada: %d) \n\n-----------------------------------------------------------------------------\n\n\n\n", sizeof(semBit), sizeof(gPlayerData));
  19. }
  20.  
  21. getArrayBit(arrayBits[], arrayIndex)
  22. {
  23.     return bool: ((arrayBits [arrayIndex / cellbits] & (1 << (arrayIndex % cellbits))) != _:false);
  24. }
  25.  
  26. setArrayBit(arrayBits[], arrayIndex, bool:arrayValue)
  27. {
  28.     return arrayBits[arrayIndex / cellbits] = !arrayValue ? arrayBits[arrayIndex / cellbits] & ~(1 << (arrayIndex % cellbits)) : arrayBits[arrayIndex / cellbits] | (1 << (arrayIndex % cellbits));
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement