// Bit/Byte utility operations for myparport driver // Author: Jayanta Konjengbam // All rights reserved #include "stddcls.h" #include "BitUtilsWdm.h" /* Verify if the bit field indicated by mask/offset is high */ BOOLEAN IsBitSet(UCHAR byte, UCHAR bitMask) { return ((byte & bitMask) ? TRUE : FALSE); } /* Put the bit field indicated by flag mask/offset to high, if low */ UCHAR SetBit(UCHAR byteValue, UCHAR bitMask) { if (!IsBitSet(byteValue, bitMask)) return (0x00|(byteValue | (bitMask))); return byteValue; } /* Multiple bits can be set at one go using this function */ VOID SetBits(PUCHAR pByteValue, UCHAR bitMasks) { USHORT i = 0; for(i=0;i> 1)); byteTmp |= (0x00 | ((byteValue & BIT_5_SET) >> 3)); byteTmp |= (0x00 | ((byteValue & BIT_6_SET) >> 5)); byteTmp |= (0x00 | ((byteValue & BIT_7_SET) >> 7)); return byteTmp; } PCHAR AllocByteToBinaryStr(UCHAR byteValue) { #define BYTE_SIZE 8 // Eight bit fields const CHAR HIGH = '1'; const CHAR LOW = '0'; PCHAR pTmp = NULL; USHORT index = 0; BOOLEAN BitHigh = FALSE; // User must free this allocation pTmp = (PCHAR)ExAllocatePool(NonPagedPool, sizeof(CHAR)*(BYTE_SIZE+1)); if (!pTmp) return NULL; for(index = 0; index < BYTE_SIZE; index++) { BitHigh = (byteValue & ((UCHAR)BIT_MASKS_ARRAY[index])); pTmp[index] = (BitHigh) ? HIGH : LOW; } // Null terminate the string pTmp[index] = '\0'; return pTmp; }