ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


new:bits

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
new:bits [2018/02/18 19:00] – created korshunnew:bits [2018/02/19 12:25] korshun
Line 1: Line 1:
 ====== Bit functions ====== ====== Bit functions ======
  
-These functions allow you to work with variables as if they were arrays of bits.+===== Working with bit arrays =====
  
-  * ''bool getbit(int a, int i)'' -- returns bit ''a[i]'' +These functions allow you to work with variables as if they were arrays of bits: 
-  * ''void setbit(int a, int i)'' -- performs ''a[i] = 1'' + 
-  * ''void clrbit(int a, int i)'' -- performs ''a[i] = 0'' +  * ''bool getbit(int a, int i)'' -- returns bit ''a[i]''. 
-  * ''void tglbit(int a, int i)'' -- performs ''a[i] = !a[i]''+  * ''int setbit(int a, int i)'' -- performs ''a[i] = 1'' and returns the result. 
 +  * ''int clrbit(int a, int i)'' -- performs ''a[i] = 0'' and returns the result. 
 +  * ''int tglbit(int a, int i)'' -- performs ''a[i] = !a[i]'' and returns the result. 
 + 
 +===== Unsetting bit flags ===== 
 + 
 +''void notflag(int flags, int flag)'' 
 + 
 +Bit flags can be applied using ''flags & SOMEFLAG''. But removing them requires a more complicated expression ''!(flags & SOMEFLAG)''
 + 
 +''notflag(flags, SOMEFLAG)'' unsets SOMEFLAG, shorthand for ''!(flags & SOMEFLAG)''.
new/bits.txt · Last modified: 2018/02/19 12:29 by korshun