簡體   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