Byte to bit array problem
-
I am experienceing a problem breaking up three bytes of data into bit arrays and assigning a value to an enumeration as a result, code shown bellow:
if (UpdateLEDAndBeepStatus != null)
{
BitArray byte0 = new BitArray(commandData.Data[0]);
BitArray byte1 = new BitArray(commandData.Data[1]);
BitArray byte2 = new BitArray(commandData.Data[2]);enumLEDAndBuzzer\[\] LEDAndBuzz\_enumArray = new enumLEDAndBuzzer\[15\]; // byte 0 bit 0 if (byte0\[0\] == true) //byte0.Count .Get(8-8) { LEDAndBuzz\_enumArray\[0\] = enumLEDAndBuzzer.BUZZER\_STATE\_ON; } else { LEDAndBuzz\_enumArray\[0\] = enumLEDAndBuzzer.BUZZER\_STATE\_OFF; } // byte 0 bit 1 if (byte0\[1\] == true) //byte0.Count { LEDAndBuzz\_enumArray\[1\] = enumLEDAndBuzzer.LED1\_MCUEnable\_ON; } else { LEDAndBuzz\_enumArray\[1\] = enumLEDAndBuzzer.LED1\_MCUEnable\_OFF; }
When the project gets to this stage the values in the bytes are "255". Should that not mean all 8 bits will be true? However my code never enters the true section of my if statement claiming "byte0[0]" is false. Either that or i am going about checking the bit values wrong, can anyone help? Thanx George :)
-
I am experienceing a problem breaking up three bytes of data into bit arrays and assigning a value to an enumeration as a result, code shown bellow:
if (UpdateLEDAndBeepStatus != null)
{
BitArray byte0 = new BitArray(commandData.Data[0]);
BitArray byte1 = new BitArray(commandData.Data[1]);
BitArray byte2 = new BitArray(commandData.Data[2]);enumLEDAndBuzzer\[\] LEDAndBuzz\_enumArray = new enumLEDAndBuzzer\[15\]; // byte 0 bit 0 if (byte0\[0\] == true) //byte0.Count .Get(8-8) { LEDAndBuzz\_enumArray\[0\] = enumLEDAndBuzzer.BUZZER\_STATE\_ON; } else { LEDAndBuzz\_enumArray\[0\] = enumLEDAndBuzzer.BUZZER\_STATE\_OFF; } // byte 0 bit 1 if (byte0\[1\] == true) //byte0.Count { LEDAndBuzz\_enumArray\[1\] = enumLEDAndBuzzer.LED1\_MCUEnable\_ON; } else { LEDAndBuzz\_enumArray\[1\] = enumLEDAndBuzzer.LED1\_MCUEnable\_OFF; }
When the project gets to this stage the values in the bytes are "255". Should that not mean all 8 bits will be true? However my code never enters the true section of my if statement claiming "byte0[0]" is false. Either that or i am going about checking the bit values wrong, can anyone help? Thanx George :)
Try:
BitArray byte0 = new BitArray(new byte\[\] {commandData.Data\[0\]});
I think that what your original line does is to create a BitArray of size 255, not one of size 8 containing 255.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Try:
BitArray byte0 = new BitArray(new byte\[\] {commandData.Data\[0\]});
I think that what your original line does is to create a BitArray of size 255, not one of size 8 containing 255.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
your thinking has been correct. I know so by reading the documentation, something everyone should do from time to time. :laugh:
Luc Pattyn
:badger: :jig: :badger:
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
:jig: :badger: :jig:
-
your thinking has been correct. I know so by reading the documentation, something everyone should do from time to time. :laugh:
Luc Pattyn
:badger: :jig: :badger:
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
:jig: :badger: :jig:
Luc Pattyn wrote:
your thinking has been correct
That's nice to know. I shall note this rare occurrence in my diary. :)
Luc Pattyn wrote:
I know so by reading the documentation, something everyone should do from time to time.
So did I, but without trying, or seeing, all of the OPs code, I can never be sure.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Luc Pattyn wrote:
your thinking has been correct
That's nice to know. I shall note this rare occurrence in my diary. :)
Luc Pattyn wrote:
I know so by reading the documentation, something everyone should do from time to time.
So did I, but without trying, or seeing, all of the OPs code, I can never be sure.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
Yeah I often regret the declarations aren't included in the code snippet.
Henry Minute wrote:
That's nice to know
NP :)
Luc Pattyn
:badger: :jig: :badger:
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
:jig: :badger: :jig:
-
Try:
BitArray byte0 = new BitArray(new byte\[\] {commandData.Data\[0\]});
I think that what your original line does is to create a BitArray of size 255, not one of size 8 containing 255.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”