0

I am doing Eloquent JavaScript and i am at the part of correlation, so far, I got the values here but don't know how to place the index on an array,

n00 = 76 (no squirrel, no pizza) 
n01 = 9 (no squirrel, pizza) 
n10 = 4 (squirrel, no pizza) 
n11 = 1 (squirrel, pizza) 

but I don;t get how to place its' indexes, and i found the annotated version, here it is:

00 → 0   // Both digits are 0. 0 + 0 = 0.
01 → 1   // There’s a 1 in the 20 position. 0 + 20 = 1. - I don't get this 20s
10 → 2   // There’s a 1 in the 21 position. 21 + 0 = 2 - I don't get this
11 → 3   // There’s a 1 in both spots. 21 + 20 = 3. - I don't get this

So our array should look like this:

[76, 9, 4, 1] 

How did this happen? why 20s? please help me understand,

1
  • I think it is 2 to the power 0 and not 20, same for 21(2 to the power 1). Commented May 31, 2016 at 9:49

1 Answer 1

2

It's not 20, it's 20. And, similarly, 21 instead of 21.

11 → 3 // There’s a 1 in both spots. 21 + 20 = 3

  • 21 is 2.
  • 20 is 1.
  • 2 + 1 = 3. See?

Must be formatting problem in the original material.

Update:

It is a formatting problem in the question, not the original material. Here's the piece from the annotated version:

enter image description here

Indexes of bits in binary representation (which also serve as values for powers of 2) start from right to left, with 0 being the rightmost index.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.