I'm trying to use the FHT library to produce a frequency spectrum of an audio signal by following an example here. After reading the ADCL and ADCH registers, the contents are combined into an int, k.
byte m = ADCL;
byte j = ADCH;
int k = (j << 8) | m;
I'm happy so far. This is then supposedly converted to a 16-bit signed integer, but I just cannot follow the logic.
k -= 0x0200;
k <<= 6;
I was expecting some bitwise inversion and then adding 1.
By hand, as far as I can tell...
0x3FF (Full scale ADC) converts to 0x7FC0 (32,704), which is close enough to 32,767 I suppose.
0x001 (smallest possible ADC ) converts to 0x8040 (I think), which is -32,704.
So, is this a widely accepted approximation or have I mis-calculated or missed the point? I've searched but haven't found this method anywhere else.