contributed by < leewei05
>
linux2022
已知我們使用的微處理器架構為 64 位元,且 unsigned long 為 8 位元組寬度 (符合 LP64 資料模型),以下是可能的 GENMASK 巨集的定義:
首先 GENMASK 代入(6, 4) 先右移 57 再左移 4
接著 GENMASK 代入(39, 21) 先右移 24 再左移 21
LEFT = 63 - h
RIGHT = l
以下取自 Linux Kernl 程式碼
考慮以下程式碼:
考慮以下程式碼,能將輸入的 8 位元無號整數逐一位元反轉,如同 LeetCode 190. Reverse Bits 的描述。
前後四位元進行互換 x = (x >> 4) | (x << 4);
。0xCC
的二進制為 11001100
,0xAA
的二進制為 10101010
。推斷 EXP2 = (x & 0x33) << 2)
, EXP3 = (x & 0x55) << 1)
因為依序是左右互換 4, 2, 1 的位元。
考慮 ilog32 函式可針對給定的 32 位元無號數,計算扣除開頭的 0,最少需要多少位元才可儲存 (the minimum number of bits required to store an unsigned 32-bit value without any leading zero bits),以下是一個可能的實作:
6.5.8 Relational operators
Each of the operators < (less than), > (greater than), <= (less than or equal to), and >=
(greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false.92)
The result has type int.
如果 v > 0
則 ret
為 1; v <= 0
則 ret
為 0。
0xFFFFU
全為 1 的 16 位元數