Click here to Skip to main content
15,902,299 members
Home / Discussions / C#
   

C#

 
Questionwhere do i wrong with registry key? Pin
Sasuko17-May-05 6:18
Sasuko17-May-05 6:18 
AnswerRe: where do i wrong with registry key? Pin
leppie17-May-05 6:24
leppie17-May-05 6:24 
GeneralRe: where do i wrong with registry key? Pin
Sasuko17-May-05 6:29
Sasuko17-May-05 6:29 
GeneralRe: where do i wrong with registry key? Pin
Sasuko17-May-05 6:36
Sasuko17-May-05 6:36 
AnswerRe: where do i wrong with registry key? Pin
OMalleyW17-May-05 6:28
OMalleyW17-May-05 6:28 
GeneralConvert byte array to bits Pin
Asad Hussain17-May-05 6:04
Asad Hussain17-May-05 6:04 
GeneralRe: Convert byte array to bits Pin
Marc Clifton17-May-05 7:42
mvaMarc Clifton17-May-05 7:42 
GeneralRe: Convert byte array to bits Pin
Asad Hussain17-May-05 8:46
Asad Hussain17-May-05 8:46 
Thanks Marc, this seems to do the trick but if any1 has a suggestion to make this process faster and less complicated then go right ahead.

private byte[ ] EncodeArray( byte[ ] parentArray )
{
    byte[ ] retArr = new byte[ parentArray.Length * 8 / 5 ];
    int i = 0;
    int pos = 0;

    while ( i < parentArray.Length )
    {
        if ( i % 5 == 0 )
        {
            byte mask = 0xF8; //11111000
            int result = parentArray[ i ] & mask ;
            retArr[ pos++ ] = ( byte ) result;

            mask = 0x7; //111
            byte mask2 = 0xC0; //11000000
            int result1 = parentArray[ i ] & mask ;
            int result2;
            if ( i + 1 < parentArray.Length )
            {
                result2 = parentArray[ i + 1 ] & mask2 ;
            }
            else
                result2 = 0;
            result = ( result1 << 2 ) + ( result2 >> 6);
            retArr[ pos++ ] = ( byte ) result;
        }
        else if ( i % 5 == 1 )
        {
            byte mask = 0x3E; //111110
            int result = parentArray[ i ] & mask;
            retArr[ pos++ ] = ( byte ) result;

            mask = 0x1; // 1
            byte mask2 = 0xF0; //11110000
            int result1 = parentArray[ i ] & mask;
            int result2;
            if ( i + 1 < parentArray.Length )
            {
                result2 = parentArray[ i + 1 ] & mask2 ;
            }
            else
                result2 = 0;
            result = ( result1 << 4 ) + ( result2 >> 4 );
            retArr[ pos++ ] = ( byte ) result;
        }
        else if ( i % 5 == 2 )
        {
            byte mask = 0xF;    //00001111
            byte mask2 = 0x80;  // 10000000
            int result1 = parentArray[ i ] & mask;
            int result2;
            if ( i + 1 < parentArray.Length )
            {
                result2 = parentArray[ i + 1] & mask2;
            }
            else
                result2 = 0;
            int result = ( result1 << 1 ) + ( result2 >> 7 );
            retArr[ pos++ ] = ( byte ) result;
        }
        else if ( i % 5 == 3 )
        {
            byte mask = 0x7C; //1111100
            int result = parentArray [ i ] & mask;
            retArr[ pos++ ] = ( byte ) result;

            mask = 0x3; //11
            byte mask2 = 0xE0; //11100000
            int result1 = parentArray[ i ] & mask;
            int result2;
            if ( i + 1 < parentArray.Length )
            {
                result2 = parentArray[ i + 1] & mask2;
            }
            else
                result2 = 0;
            result = ( result1 << 2 ) + ( result2 >> 5 );
            retArr[ pos++ ] = ( byte ) result;
        }
        else if ( i % 5 == 3 )
        {
            byte mask = 0x1F; //11111
            int result = parentArray [ i ] & mask;
            retArr[ pos++ ] = ( byte ) result;
        }
        i++;
    }

    return retArr;
}

GeneralRe: Convert byte array to bits Pin
Marc Clifton18-May-05 2:09
mvaMarc Clifton18-May-05 2:09 
GeneralRe: Convert byte array to bits Pin
Robert Rohde17-May-05 11:26
Robert Rohde17-May-05 11:26 
Generalfeedback Pin
niansah17-May-05 4:54
niansah17-May-05 4:54 
GeneralRe: feedback Pin
Robert Rohde17-May-05 4:59
Robert Rohde17-May-05 4:59 
GeneralRe: feedback Pin
niansah17-May-05 5:03
niansah17-May-05 5:03 
GeneralRe: feedback Pin
Colin Angus Mackay17-May-05 5:48
Colin Angus Mackay17-May-05 5:48 
GeneralReading all particular nodes with loop Pin
ksanju100017-May-05 3:23
ksanju100017-May-05 3:23 
GeneralRe: Reading all particular nodes with loop Pin
Marc Clifton17-May-05 3:34
mvaMarc Clifton17-May-05 3:34 
GeneralRe: Reading all particular nodes with loop Pin
mav.northwind17-May-05 3:52
mav.northwind17-May-05 3:52 
GeneralRe: Reading all particular nodes with loop Pin
niansah17-May-05 4:23
niansah17-May-05 4:23 
GeneralC#, LDAP, and Active Directory Pin
slvrscremr17-May-05 3:13
slvrscremr17-May-05 3:13 
GeneralRe: C#, LDAP, and Active Directory Pin
Scott Serl17-May-05 21:23
Scott Serl17-May-05 21:23 
GeneralNeed to Read XML File Pin
Jethro6317-May-05 2:37
Jethro6317-May-05 2:37 
GeneralRe: Need to Read XML File Pin
Robert Rohde17-May-05 3:17
Robert Rohde17-May-05 3:17 
GeneralRe: Need to Read XML File Pin
Jethro6317-May-05 3:21
Jethro6317-May-05 3:21 
GeneralRe: Need to Read XML File Pin
Marc Clifton17-May-05 3:22
mvaMarc Clifton17-May-05 3:22 
GeneralRe: Need to Read XML File Pin
niansah17-May-05 3:45
niansah17-May-05 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.