Click here to Skip to main content
15,914,070 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to call GetBitsToByteValue on click event. So how can i call it in click event ?
C#
private void mtlBtnLogin_Click(object sender, EventArgs e)
       {



}

C#
public static byte[] GetBitsArray(byte value)
{
    if (value == 0) return new byte[0];
    byte[] bArray = { value };
    BitArray objBitArray = new BitArray(bArray);
    byte[] bResult = new byte[objBitArray.Count];
    for (int iCount = 0; iCount < objBitArray.Count; iCount++)
    {
        bResult[iCount] = Convert.ToByte(objBitArray[iCount]);
    }
    return bResult;
}
public static byte GetBitsToByteValue(bool bit0, bool bit1, bool bit2, bool bit3, bool bit4, bool bit5, bool bit6, bool bit7)
{
    bool[] blArray = { bit0, bit1, bit2, bit3, bit4, bit5, bit6, bit7 };
    byte value = 0x00;
    for (byte x = 0; x < 8; x++)
    {
        value |= (byte)((blArray[x]) ? (0x01 << x) : 0x00);
    }
    return value;
}
public static byte GetBitsToByteValue(params bool[] blArray)
{
    byte value = 0x00;
    for (byte x = 0; x < blArray.Length; x++)
    {
        value |= (byte)((blArray[x]) ? (0x01 << x) : 0x00);
    }
    return value;
}
public static byte ConvertToByte(BitArray bits)
{
    if (bits.Count != 8)
    {
        return 1;
    }
    byte[] bytes = new byte[1];
    bits.CopyTo(bytes, 0);
    return bytes[0];
}
Posted
Updated 28-Jun-10 23:38pm
v5
Comments
Sandeep Mewara 29-Jun-10 2:27am    
Question is unclear. Please add more details of what you are trying to do.

It depends on what you need to do - since no one here is aware of that answering this question is not possible.
 
Share this answer
 
Well, the simple answer is:

C#
private void mtlBtnLogin_Click(object sender, EventArgs e)
{
    byte x = GetBitsToByteValue(true, false, false, false, true, true, true,false);

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900