core: Fix bitarithm and unittests

I was unable to find a more efficient implementation for now, so I reverted back to the old implementation. I also removed some flaws from the unittests for this module.