Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

binary addition algo

1 view
Skip to first unread message

presidentbyamendment

unread,
Dec 5, 2019, 11:19:37 PM12/5/19
to

# I haven't seen this before. Have you?
#
# segregated AND/XOR addition

# This algorithm adds two numbers using AND and exclusive OR to
# segregate cases of 1:1 pairs from the other three possibilities and
# shifting all the 1:1s in parallel, thus performing many carries in a
# single shift. Repeating the processes until the AND result is zero
# processes 1:1 pairs generated in intermediate results and produces
# the sum of two inputs, often in just a few iterations.

# written in Bash in Linux in a Termux app. That's a 64 bit Bash.
# . thisfile
# A=2239792374 B=8458758
# sax+


sax+ () {

let E=$A+$B
printf "The sum from Bash + is "%d"\n" $E
let AA=$A
let BB=$B
C=20
let i=0
while test $C -ne 0
do
let i=$i+1
printf %x" "%x" "%x" \n" $i $AA $BB

let D=$AA^$BB # XOR
let CC=$AA\&$BB # AND
let C=$CC\<\<1 # upshift 1
let AA=$C
let BB=$D

done
printf " segregated AND/XOR addition result ..."%d"\n" $D
}

## Rick presidentbyamendment Hohensee
0 new messages