I'm working in C and need to add and subtract a 64-bit number and a 128-bit number. The result will be held in the 128-bit number. I am using an integer array to store the upper and lower halves of the 128-bit number (i.e. uint64_t bigNum[2]
, where bigNum[0]
is the least significant).
Can anybody help with an addition and subtraction function that can take in bigNum and add/subtract a uint64_t
to it?
I have seen many incorrect examples on the web, so consider this:
bigNum[0] = 0;
bigNum[1] = 1;
subtract(&bigNum, 1);
At this point bigNum[0]
should have all bits set, while bigNum[1]
should have no bits set.