Marko Rauhamaa <ma...@pacujo.net> writes: > The basic arithmetic algorithms are independent of the base.
Right. > For example, here's how you can add two 128-bit integers in C using > 64-bit digits: > > typedef struct { > uint64_t lo, hi; > } uint128_t; > > uint128_t add128(uint128_t x, uint128_t y) > { > uint128_t result = { > .lo = x.lo + y.lo, > .hi = x.hi + y.hi > }; > if (result.lo < x.lo) > result.hi++; > return result; > } > > Works both for signed and unsigned integers. (Slightly off-topic, but...) No, it would not work for signed integers (i.e., with lo and hi of int64_t type), because overflow is undefined behavior for signed. -- Alain. -- https://mail.python.org/mailman/listinfo/python-list