我需要帮助来计算处理器亲和力值
0 (0000) Not allowed (that would mean use no processors)
1 (0001) Use processor 1
2 (0010) Use processor 2
3 (0011) Use both processors 1 and 2
4 (0100) Use processor 3
5 (0101) Use both processors 1 and 3
6 (0110) Use both processors 2 and 3
7 (0111) Use processors 1,2 and 3
8 (1000) Use processor 4
1,2,3,结果为7.我想知道什么是公式?
答案 0 :(得分:1)
这似乎是一个简单的4位binary number。
最右侧位置的1表示1,距右侧装置2的第二个位置1表示,第3个表示4表示位于第4个位置,右侧表示第4个位置(即左侧第一个数字)表示8总价值就是所有这些头寸的总和。
基本思想(在伪代码中,因为我们无法正确格式化公式):
totalValue
for every digit at position i (counted from the right, starting with 0)
totalValue = totalValue + 2^i*(digit at position i)
例如3(0011
),值为0x2^3 + 0x2^2 + 1*2^1 + 1*2^0 = 0 + 0 + 2 + 1 = 3
例如4(0100
),值为0x2^3 + 1x2^2 + 0*2^1 + 0*2^0 = 0 + 4 + 0 + 0 = 4
答案 1 :(得分:0)
Processor_Affinity := Use_processor_1 + Use_processor_2 + Use_processor_3
答案 2 :(得分:0)
所以1010;将其解释为:
0 at 1st position as OFF
1 at 2nd position as ON
0 at 3rd position as OFF
1 at 4th position as ON