Y
Y
youngblood2017-03-14 23:42:31
Programming
youngblood, 2017-03-14 23:42:31

How to insert before each bit in a number, three zero bits?

For example, there is a number:
a = 10101111 (bin - 8 bit) It is
necessary to insert three zero bits after each bit of the number using bit operations to get it like this:
b = 00010000000100000001000100010001 (bin - 32 bit)
How can I do this for any numbers "a" eight bit?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-03-15
@youngblood

unit32_t sparse(uint8_t src) {
  uint32 dst = src;
  dst = ((dst & 0xF0) << 12) | (dst & 0xF);
  dst = ((dst & 0xC000C) << 6) | (dst & 0x30003);
  dst = ((dst & 0x2020202) << 3) | (dst & 0x1010101);
  return dst;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question