- Aug
- 2,320
- 111
To keep my mind active,
here's my method of addition
using only bit manipulation.
Output;
Joe
here's my method of addition
using only bit manipulation.
Code:
@setlocal
@echo off
set num1=1989
set num2=35
do while %num2 ne 0
set carry=%@eval[%num1 & %num2]
set num1=%@eval[%num1 ^ %num2]
set num2=%@eval[%carry << 1]
echo carry: %carry
echo num1: %num1
echo num2: %num2
pause
enddo
echo num1: %num1
endlocal
Output;
Code:
R:\>test.btm
carry: 1
num1: 2022
num2: 2
Press any key when ready...
carry: 2
num1: 2020
num2: 4
Press any key when ready...
carry: 4
num1: 2016
num2: 8
Press any key when ready...
carry: 0
num1: 2024
num2: 0
Press any key when ready...
num1: 2024
Joe
Last edited: