掩蔽最显著位 [英] masking most significant bit
本文介绍了掩蔽最显著位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写此功能来消除最显著位的每一个字节。但这个功能似乎并不奏效,我想它是的方式。
I wrote this function to remove the most significant bit in every byte. But this function doesn't seem to be working the way I wanted it to be.
输出文件的大小始终是'0',我不明白为什么什么也没有被写入到输出文件。有没有更好的和简单的方法来消除每一个字节?
The output file size is always '0', I don't understand why nothing's been written to the output file. Is there a better and simple way to remove the most significant bit in every byte??
推荐答案
,这种经历只有 1
位。 高()
如果参数为零返回参数的高位,或零。
Instead of going through all of the bits to find the high one, this goes through only the 1
bits. high()
returns the high bit of the argument, or zero if the argument is zero.
inline int high(int n)
{
int k;
do {
k = n ^ (n - 1);
n &= ~k;
} while (n);
return (k + 1) >> 1;
}
inline int drop_high(int n)
{
return n ^ high(n);
}
这篇关于掩蔽最显著位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文