S
S
samarjan2016-04-09 21:37:39
Atmel AVR
samarjan, 2016-04-09 21:37:39

How to form a byte of data from one bit of another byte?

I can not formulate an algorithm for the formation of one byte. It is necessary to read the bits from the foot of the MK and form a byte from them, but the hardware capability cannot be used. It simplifies the task, of course, that the bit to be read is always in the same place in the byte. Let me explain with an example:
I have a variable For each cycle , I receive bytes and
char data;
there will be 8 pieces in total , for example :








I need to track the bit in bold and put it in the right place in the data variable, and as a result, the variable should be like this: But I can’t make an algorithm, I hope the community can help
data == 0b01100010

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-04-09
@alsopub

char inbyte = 0b00100101;
char data = 0b01100010;
data = (data & 0b01111111) | ((inbyte & 0b00000100) << 5);

result - 0b11100010;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question