2011-02-14 97 views
0

我需要帮助来计算的处理器关联值二进制计算

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,2和3导致7,因为3代表1和2,所以它应该是1,2,4使用二进制OR导致0111是7。 –

+2

*有1,2,3,结果是7. * ?? – aioobe

+0

“3”是这个上下文中的一个位置,它由二进制中的“0100”表示,它是十进制的4。 – karatedog

回答

1

它似乎是一个简单的4位数binary number

位于最右边位置的1表示1,右边第二个位置上的1表示2,第三个表示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

+0

哎呀,谢谢aioobe。 –

+0

那么如何计算它,例如:3,4? – StoneHeart

0
Processor_Affinity := Use_processor_1 + Use_processor_2 + Use_processor_3 
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