I understand that 1 byte will hold a number from 0-255. And that a 16-bit number is between 0-65535.
If I'm trying to represent a 16-bit number using two separate 8-bit registers...how do I do that? How does the math work?
The math works out as follows:
with shifts and bitwise operations:
In most CPUs, even some archaic 8-bit ones, this interpretation is done in hardware: you load bytes into parts of a 16-bit register or into separate 8-bit registers that can work as a 16-bit pair, and the hardware works with the data as if it were a single 16-bit number.
In decimal how do I take 7 and 9 and make 79? (7*10)+9 Or 12 and 34 and make 1234? (12*100)+34. No different 0x12 and 0x34 and make 0x1234. (0x12 * 0x100) + 0x34. Much cleaner to bit shift (0x12 << 8 ) + 0x34. you can or it is as well (0x12<<8) | 0x34.
You want to work with them together? It's easy
Let's say you have the number 2643 - in base 10. if you break it into halves, you will have something like 26 and 43, right? well you know that if you multiply by two, you have to multiply from right to left, and carry. So do that - multiply the right side, and if there is overflow, add that to the left side and then multiply the left side.
See how that worked? Same goes for division - need to carry? Steal from the higher bit. Want to add or subtract numbers? Not so hard after all!
Binary numbers work the same way.
Basically you calculate the lower end, then calculate the upper end, then you apply the overflow.