Hi, I'm trying to create the array twoToThe[j] whose jth location represent 2 to power of j. What's the integer value for twoToThe? It should be the integer representation of binary code 1 followed by 15 zeros. I thought it's -32768. However the compiler complains "Integer constant too big". What's the correct constant? Any help is greatly appreciated!
You are correct, the binary value 1000 0000 0000 0000 is -32768 in 2's-complement. But the Jack compiler can't handle it because the '-' is actually unary negation and 32768 is not a legal positive integer.
What you can do is 32767+1 or ~32767.
Also note that if you are using
let twoToThe[j+1] = twoToThe[j]+twoToThe[j];
to initialize the array, 16384+16384 will result in -32768.