Moving a bit within a byte using bitfield or bitwise operators
问题 Is there an elegant way of moving a bit within a byte (or word/long). For simplicity, lets use a simple 8-bit byte and just one bit to move within the byte. Given a bit number, based on 0-7 Least-sig-bit to most-sig-bit, (or bits 1-8 if you'd rather), I would like to move a bit from one position to another: 7654 3210 <bit position 0101 1010 <some binary value --x- --y- <move bit from x to y 0111 0100 <new value with x moved to y and intervening bits shifted left So, x at bit position 5 moves