I have code working that adds two unsigned 64-bit numbers together, by splitting them into two separate 32-bit numbers (stored in two Longs each), adding those split parts, adding any overflow from the lower part to the upper part, and then combinging them (or).
I am trying to do the same thing with subtracting the two numbers but it's proving a bit difficult.
Both numbers are 64-bit unsigned and must remain so. One number is subtracted from the other, and then there are actions to take based on the result. If the result would be <0, 2^64 should be added to the value to `wrap it`, or in another case, if the number is <0 it becomes zero (easy enough). I achieve this I don't want a whole bunch of If statements, it should be done using shifts, and's, or's, etc.
I just cant quite figure out the combination to split the data up, do the subtraction and preserve the sign, then combine it all back together properly. The end result has to be written out to memory.
So I just thought I'd throw it out there, maybe someone can suggest a technique? I also have to do the same thing to accomodate 63-bit numbers.
Thanks
I am trying to do the same thing with subtracting the two numbers but it's proving a bit difficult.
Both numbers are 64-bit unsigned and must remain so. One number is subtracted from the other, and then there are actions to take based on the result. If the result would be <0, 2^64 should be added to the value to `wrap it`, or in another case, if the number is <0 it becomes zero (easy enough). I achieve this I don't want a whole bunch of If statements, it should be done using shifts, and's, or's, etc.
I just cant quite figure out the combination to split the data up, do the subtraction and preserve the sign, then combine it all back together properly. The end result has to be written out to memory.
So I just thought I'd throw it out there, maybe someone can suggest a technique? I also have to do the same thing to accomodate 63-bit numbers.
Thanks