J
johannblake
I have a variable that is 1 bit wide. I also have a variable that is a
byte. I want to shift the bits out of the byte into the bit variable
(one at a time) but am not sure how to do this or whether it is even
possible. Here is what my code looks like:
// data is a variable 1 byte in size while bitVariable is 1 bit in
size. i is a byte.
for (i = 0; i < 8; i++)
{
bitVariable = (data << i) & 0x80;
}
I don't believe this will work because there is no indication what is
really being assigned to bitVariable. My compiler doesn't complain and
I find that strange. Essentially, I need to shift the bits in "data" to
an output port on my microcontroller and want to do it as quickly as
possible.
byte. I want to shift the bits out of the byte into the bit variable
(one at a time) but am not sure how to do this or whether it is even
possible. Here is what my code looks like:
// data is a variable 1 byte in size while bitVariable is 1 bit in
size. i is a byte.
for (i = 0; i < 8; i++)
{
bitVariable = (data << i) & 0x80;
}
I don't believe this will work because there is no indication what is
really being assigned to bitVariable. My compiler doesn't complain and
I find that strange. Essentially, I need to shift the bits in "data" to
an output port on my microcontroller and want to do it as quickly as
possible.