Bit Helper : Binary Bit « Data Types « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Data Types » Binary BitScreenshots 
Bit Helper
 
//GNU Library General Public License (LGPL)
//http://dac.codeplex.com/license
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);
        }
    }
}

   
  
Related examples in the same category
1.Using the Bitwise Complement Operators with Various Data TypesUsing the Bitwise Complement Operators with Various Data Types
2.Obtaining the Most Significant or Least Significant Bits of a NumberObtaining the Most Significant or Least Significant Bits of a Number
3.Binary Data TestBinary Data Test
4.Binary Network Byte OrderBinary Network Byte Order
5.Int binary
6.Get hash code for a byte array
7.Clone a byte array
8.Count the number of bit
9.Bit shifting for int and long value
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.