Added a second version that uses the high bits of the carry to keep state