繁体   English   中英

如果最高有效字节的最高有效位为 1,则样本为负

[英]if the most-significant bit of most-significant byte is 1, then sample is negative

嗨,我正在做一个关于音频处理的项目

代码工作正常,但我不明白这三行

如果有人知道这些代码行的内容

// Otherwise, if the most-significant bit of most-significant byte is 1, then
// sample is negative, so we need to set the upper bytes to all 1s.
else if (sampleBytes[bytesPerSample-1] & 0x80)
{
    for (size_t b = bytesPerSample; b < sizeof(sample); b++)
    {
        sampleBytes[b] = 0xFF;
    }
}

如果它是负数,那几行将带有放置在 'sampleBytes' 中的 'bytesPerSample' 字节数扩展到与 'sample' 变量一样多的字节数。

在大多数系统中,负数以二进制补码形式表示( https://en.wikipedia.org/wiki/Two%27s_complement )。 也就是说,-x = NOT(x) + 1。

For example:
11111111 = 1
11111110 = 2
11111101 = 3
11111100 = 4
...

因此,如果数字为负数,则必须用要扩展的数字来完成,以保持该值。

第一行断言数字是否为负数,第二行迭代额外的字节,最后一行将这些字节放入十六进制。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM