All pastes #572618 Raw Edit

losl

public c v1 · immutable
·published 2007-06-17 19:31 UTC
rendered paste body
// inc_bitflags// Scripts for handling and manipulating an array of boolean values// As stored in an integer.// Stephen Jackson / losl// blade2k.losl@gmail.comconst int BITFLAGS_MAX_ARRAY_INDEX = 31;//BITFLAG_GetStatus//Arguments://nFlag - Bit to check//nBitArray - Integer for bitarry//Returns a boolean status for that flagint BITFLAG_GetStatus(int nFlag, int nBitArray);//BITFLAG_ComparsionArray//Arguments://nFlag - Bit To Enable//Returns an integer with only bit nFlag Enabled.int BITFLAGS_ComparisonArray(int nFlag);//BITFLAGS_Switch//Arguements://nFlag - Bit To Change//bNewStatus - What to make that bit//nBitArray - The array to work with//Returns an updated Bit Array.int BITFLAGS_Switch(int nFlag, int bNewStatus, int nBitArray);//DEFINITIONSint BITFLAG_GetStatus(int nFlag, int nBitArray){    int nFlagCheck; //Varible for storing our bitwise comparison.    int nCompare = nBitArray;    //Make sure we're checking a legal flag    if(nFlag < 0 || nFlag >= BITFLAGS_MAX_ARRAY_INDEX)        nFlag = 0;    //Check All the BitArrays to make sure they are > 0;    if(nBitArray < 0)        nBitArray = 0;    //Make our bitwise comparison integer    nFlagCheck = BITFLAGS_ComparisonArray(nFlag);    if((nFlagCheck & nCompare) == nFlagCheck)        return 1;    else        return 0;}int BITFLAGS_ComparisonArray(int nFlag){    return FloatToInt(pow(2.0, IntToFloat(nFlag)));}int BITFLAGS_Switch(int nFlag, int bNewStatus, int nBitArray){    int nFlagCheck;    int bStatus;    //Legalize    if(nFlag < 0 || nFlag  >= BITFLAGS_MAX_ARRAY_INDEX)        nFlag = 0;    //Check All the BitArrays to make sure they are > 0;    if(nBitArray < 0)        nBitArray = 0;    //Make sure the new Status is Boolean    if(bNewStatus != 1 && bNewStatus != 0)        bNewStatus = 1;    bStatus = BITFLAG_GetStatus(nFlag, nBitArray);    if(bStatus =! bNewStatus)    {        nFlagCheck = BITFLAGS_ComparisonArray(nFlag);        if(bStatus == TRUE && bNewStatus == FALSE)            nFlagCheck *= -1;        nBitArray += nFlagCheck;    }    return nBitArray;}