Advertisement
pintcat

addition - arithmetic function which uses only logic functions

Jun 27th, 2025
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.13 KB | Science | 0 0
  1. #!/bin/sh
  2.  
  3. A=$1
  4. B=$2
  5. while [ $B -gt 0 ]; do
  6.     CARRY=$((A & B))
  7.     A=$((A ^ B))
  8.     B=$((CARRY << 1))
  9. done
  10. echo $1"+"$2"="$A
  11.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement