<分区>
代码:
PORTB = "0b11010000";
问题:
我现在正在学习在 MPLab 上使用 C 语言对 8 位微 Controller PIC18F8722 进行编程。
如何将这个二进制 PORTB 位从“11010000”镜像到“00001011”?
<分区>
代码:
PORTB = "0b11010000";
问题:
我现在正在学习在 MPLab 上使用 C 语言对 8 位微 Controller PIC18F8722 进行编程。
如何将这个二进制 PORTB 位从“11010000”镜像到“00001011”?
最佳答案
关于 C 中位运算的最佳文章是 Bit Twiddling Hacks由肖恩·埃隆·安德森 (Sean Eron Anderson) 撰写。他提供了许多类型的 Bit 函数来以优化的方式做事。他的方法在世界范围内被接受,许多图书馆使用它们以优化的方式做事。他提供的Bits逆向方式:
unsigned int v; // input bits to be reversed
unsigned int r = v; // r will be reversed bits of v; first get LSB of v
int s = sizeof(v) * CHAR_BIT - 1; // extra shift needed at end
for (v >>= 1; v; v >>= 1){
r <<= 1;
r |= v & 1;
s--;
}
r <<= s; // shift when v's highest bits are zero
其他类型查看文章
关于c - 如何在 C 上将二进制 PORTB 位从 "11010000"镜像到 "00001011"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25385931/