.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Bit Helper

Posted By:SanthoshNathan       Posted Date: November 01, 2010    Points: 15    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Bit Helper
 

using System;
using System.Security;

namespace RaisingStudio.Collections.Generic
{
    internal class BitHelper
    {
        private const byte IntSize = 0x20;
        private int[] m_array;
        private unsafe int* m_arrayPtr;
        private int m_length;
        private const byte MarkedBitFlag = 1;
        private bool useStackAlloc;

#if (PocketPC || Smartphone)
#else
        [SecurityCritical]
#endif
        internal unsafe BitHelper(int* bitArrayPtr, int length)
        {
            this.m_arrayPtr = bitArrayPtr;
            this.m_length = length;
            this.useStackAlloc = true;
        }

        internal BitHelper(int[] bitArray, int length)
        {
            this.m_array = bitArray;
            this.m_length = length;
        }

        [SecurityCritical]
        internal unsafe bool IsMarked(int bitPosition)
        {
            if (this.useStackAlloc)
            {
                int num = bitPosition / 0x20;
                return (((num < this.m_length&& (num >= 0)) && ((this.m_arrayPtr[num(((int)1<< (bitPosition % 0x20))) != 0));
            }
            int index = bitPosition / 0x20;
            return (((index < this.m_length&& (index >= 0)) && ((this.m_array[index(((int)1<< (bitPosition % 0x20))) != 0));
        }

        [SecurityCritical]
        internal unsafe void MarkBit(int bitPosition)
        {
            if (this.useStackAlloc)
            {
                int num = bitPosition / 0x20;
                if ((num < this.m_length&& (num >= 0))
                {
                    int* numPtr1 = this.m_arrayPtr + num;
                    numPtr1[0|= ((int)1<< (bitPosition % 0x20);
                }
            }
            else
            {
                int index = bitPosition / 0x20;
                if ((index < this.m_length&& (index >= 0))
                {
                    this.m_array[index|= ((int)1<< (bitPosition % 0x20);
                }
            }
        }

        internal static int ToIntArrayLength(int n)
        {
            if (n <= 0)
            {
                return 0;
            }
            return (((n - 10x201);
        }
    }
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend