I do not understand the piece of your question "--> 25 + 20". I will ignore that, and explain the rest.
The easiest way is to look at a number in binary.
The binary for 33 is "100001".
Reading this from left to right, the digits represent (1<<5), (1<<4), (1<<3), (1<<2), (1<<1) and (1<<0). (1<<0) = 1. The last digit always represents (1<<0), which is 1. So, 33 can be expressed as 1*(1<<5) + 0*(1<<4) + 0*(1<<3) + 0*(1<<2) + 0*(1<<1) + 1*(1<<0). Since 1*x=x, and 0*x=0, this can be simplified to 33=(1<<5) + (1<<0).
So these are all the same:
- 33 * N
- ((1<<5) + (1<<0)) * N
- (1<<5)*N + (1<<0)*N
- (N<<5) + (N<<0)
- (M<<5) + N
You can compare this to base 10 - I'll use 135 as an example here. "<
If we multiply 135*3 (base 10), we might say "(3*1) hundred + (3*3) tens + (3*5) ones = 300 + 90 + 15 = 405.
This method can be applied for any number, and will result in additions only. For the general case, any combination of powers-of-two that can be added or subtracted, can be added or subtracted in the same way. For example, 65599 in binary is "10000000000111111". I can see a long string of ones (at the end), so I would identify the lowest 1 in the series (in this case representing 1<<0), add it on here to make a simpler number, the subtract it again later:
- 65599 = 10000000000111111
- = 65599 +(1<<0) - (1<<0)
- = 65600 - (1<<0)
- = 10000000001000000 - (1<<0)
- = (1<<16) + (1<<6) - (1<<0)
Using addition only, you the shifts are cumulative. Since 1<<2 = (1<<1)<<1, you can follow these steps to multiply A*B:
- total=0
- Convert A to binary - e.g. convert 65599 to "10000000000111111".
- start at the most significant (left-most) bit (bit=binary digit) of A
- If the bit you are looking at is a 1, then add B to total.
- Regardless of what bit it is, multiply the total by 2 - a.k.a total=total<<1
- If the bit of A you are looking is the least significant bit, stop here - total will be your answer.
- Otherwise, look at the next bit (moving towards the right) of A, and go back to step 4.
This is how computers often multiply. Step 2 is unnecessary for computers, because that's how they store numbers all the time.
This is much quicker than multiplying by counting - you go around the loop one per bit, with 3-4 operations per loop - add B (if appropriate); double the total; move to the next bit, conditional-branch back if not complete. Since computers deal with set sizes (e.g. 64-bit), and the highest bit is shifted out into the "carry" flag, you can treat the carry as the check if you need to add or not. This means the above code reduces to:
- total=0
- do 64 times:
- A = A<<1
- if there was a carry from the above instruction, total=total+B
- total=total<<1
If you're following these instructions, pad A with zeroes on the left, to 64 bits; then when you shift-left (i.e. add a bit to the right), then the left-most bit becomes the carry.