2011-02-14 4 views
0

私はプロセッサアフィニティ値1、2、3でバイナリ計算

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 

を計算するのに助けを必要とし、結果は私が何式であるだろ7のですか?

+0

それは3は1と2を表しとして1,2および3は、7をもたらすことができないので、それはバイナリOR 7である0111をもたらす用い1,2,4であるべきです。 –

+2

* 1、2、3の場合、結果は7です。 – aioobe

+0

"3"はこの文脈での位置であり、バイナリで '0100'で表され、10進数では4です。 – karatedog

答えて

1

単純な4桁binary numberのようです。

右端の位置にある1は、右から2番目の位置にあるa1は2番目を意味し、3番目は4を意味し、右から4番目の位置(つまり、左から1番目の桁) 8.合計金額は、すべてのポジションの合計です。

基本的な考え方(擬似コードでは、我々は正しくここにフォーマット式はあることができないためには):例3(0011)の場合、値は、例えば4 0x2^3 + 0x2^2 + 1*2^1 + 1*2^0 = 0 + 0 + 2 + 1 = 3

totalValue 
for every digit at position i (counted from the right, starting with 0) 
    totalValue = totalValue + 2^i*(digit at position i) 

ある

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 
関連する問題