Last active
December 24, 2015 09:18
-
-
Save kiwipom/6775842 to your computer and use it in GitHub Desktop.
Adding numbers without using operators in haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Based on the c implementation, as per: http://stackoverflow.com/a/365544 | |
import Data.Bits | |
add' :: (Bits a) => a -> a -> a | |
add' a b | |
| a == 0 = b | |
| otherwise = add' ((a .&. b) `shiftL` 1) (a `xor` b) | |
> add' 17 13 | |
30 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a version written in x86 assembler, with a C++ wrapper.
It compiles under Visual Studio, but might need some changes to the assembly syntax for other compilers.