Quantcast
Channel: Take Command / TCC
Viewing all articles
Browse latest Browse all 1680

Addition using only bit manupulation

$
0
0
To keep my mind active,
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...

Read more

Viewing all articles
Browse latest Browse all 1680

Trending Articles