Index: /trunk/psLib/src/dataManip/Makefile
===================================================================
--- /trunk/psLib/src/dataManip/Makefile	(revision 434)
+++ /trunk/psLib/src/dataManip/Makefile	(revision 434)
@@ -0,0 +1,30 @@
+ifndef prefix
+    export prefix=$(shell cd ../..;pwd)
+endif
+
+TARGET = libpsDataManip.a
+
+all: $(TARGET)
+
+include ../Makefile.Globals
+
+SRC_OBJS = \
+    psBitMask.o \
+    psSort.o
+
+libpsDataManip.a: $(SRC_OBJS)
+	$(AR) -r libpsDataManip.a $(SRC_OBJS)
+
+install: $(TARGET)
+	install *.h $(includedir)
+	install $(TARGET) $(libexecdir)
+
+distclean:	clean
+	$(RM) $(TARGET)
+
+clean:
+	@echo "    Deleting intermediate files for 'utilities - $(CFG)'"
+	$(RM) $(SRC_OBJS) *.lint
+
+%.lint: %.c
+	splint +posixlib -exportlocal -realcompare $(INCLUDE_GLOBAL) $? > $@; cat $@ 
Index: /trunk/psLib/src/dataManip/psBitMask.c
===================================================================
--- /trunk/psLib/src/dataManip/psBitMask.c	(revision 434)
+++ /trunk/psLib/src/dataManip/psBitMask.c	(revision 434)
@@ -0,0 +1,138 @@
+#include "psBitMask.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+
+static char* getByte(int bit, const psBitMask* inMask);
+static char mask(int bit);
+
+psBitMask* psBitMaskAlloc(int n)
+{
+    psBitMask *newObj = (psBitMask*)malloc(sizeof(psBitMask));
+    newObj->n = n;
+    newObj->bits = (char*)malloc(sizeof(char)*n);
+    memset(newObj->bits, n, 0);
+    
+    return newObj;
+}
+
+void psBitMaskFree(psBitMask *restrict inMask)
+{
+    free(inMask->bits);
+    free(inMask);
+}
+
+psBitMask* psBitMaskSet(psBitMask *inMask, int bit)
+{
+    char* byte = getByte(bit, inMask);
+    *byte |= mask(bit);
+    
+    return inMask;
+}
+
+int psBitMaskTest(const psBitMask *inMask, int bit)
+{
+    char* byte = getByte(bit, inMask);
+    if((*byte&mask(bit)) == 0) {
+        return 0;
+    }
+    
+    return 1;
+}
+
+psBitMask* psBitMaskOp(psBitMask *outMask, const psBitMask *restrict inMask1, char *operator, const psBitMask *restrict inMask2)
+{
+    int i = 0;
+    int n = 0;
+    char tempChar = '0';
+    char *outBits = NULL;
+    char *inBits1 = NULL;
+    char *inBits2 = NULL;
+
+    if(outMask == NULL) {
+        printf("Null output psBitMask\n");
+        return outMask;
+    }
+    
+    if(inMask1 == NULL) {
+        printf("Null input psBitMask1\n");
+        return outMask;
+    }
+    
+    if(operator == NULL) {
+        printf("Null input operator\n");
+        return outMask;
+
+    }
+ 
+    if(inMask2 == NULL) {
+        printf("Null input psBitMask2\n");
+        return outMask;
+    }
+    
+    if(inMask1->n != inMask2->n || outMask->n != inMask1->n) {
+        printf("Mask sizes not the same\n");
+        return outMask;
+    }
+    
+    n = outMask->n;
+    outBits = outMask->bits;
+    inBits1 = inMask1->bits;
+    inBits2 = inMask2->bits;
+    
+    tempChar = toupper(*operator);
+    switch(tempChar) {
+    case 'A':
+        for(i=0; i<n; i++) {
+            outBits[i] = inBits1[i] & inBits2[i];
+        }
+        break;
+    case 'O':
+        for(i=0; i<n; i++) {
+            outBits[i] = inBits1[i] | inBits2[i];
+        }
+        break;
+    case 'X':
+        for(i=0; i<n; i++) {
+            outBits[i] = inBits1[i] ^ inBits2[i];
+        }
+        break;
+    default:
+        printf("Invalid psBitMask option %s\n", operator);
+    }
+    
+    return outMask;
+}
+
+char *psBitMaskToString(const psBitMask *restrict inMask)
+{
+    int i = 0;
+    int numBits = inMask->n*8;
+    char* outString = (char*)malloc(numBits);
+    for(i=0; i<numBits; i++) {
+        outString[numBits-i-1] = (psBitMaskTest(inMask, i))?'1':'0';
+    }
+    
+    return outString;
+}
+
+/* 0 based index of byte array's byte that contains containing bit */
+static char* getByte(int bit, const psBitMask* inMask)
+{
+    int index = 0;
+    char *byte = 0;
+    index = bit/8;
+    byte = inMask->bits+index;
+    
+    return byte;
+}
+
+static char mask(int bit)
+{
+    char mask = 0x01;
+    mask = mask << (bit%8);
+    
+    return mask;
+}
Index: /trunk/psLib/src/dataManip/psBitMask.h
===================================================================
--- /trunk/psLib/src/dataManip/psBitMask.h	(revision 434)
+++ /trunk/psLib/src/dataManip/psBitMask.h	(revision 434)
@@ -0,0 +1,13 @@
+typedef struct {
+    int n;
+    char *bits;
+} psBitMask;
+
+psBitMask* psBitMaskAlloc(int n);
+void psBitMaskFree(psBitMask *restrict inMask);
+psBitMask* psBitMaskSet(psBitMask *inMask, int bit);
+int psBitMaskTest(const psBitMask *inMask, int bit);
+psBitMask* psBitMaskOp(psBitMask *outMask, const psBitMask *restrict inMask1, char *operator, const psBitMask *restrict inMask2);
+char *psBitMaskToString(const psBitMask *restrict inMask);
+static char* getByte(int bit, const psBitMask* inMask);
+static char mask(int bit);
