public void updateChecksum(Memory memory, AddressSetView addrSet, TaskMonitor monitor,
			boolean xor, boolean carry, boolean onesComp, boolean twosComp)
			throws MemoryAccessException, CancelledException {

		long sum = 0;
		int i = 0;
		MemoryByteIterator bytes = new MemoryByteIterator(memory, addrSet);
		while (bytes.hasNext()) {
			if (monitor.isCancelled()) {
				throw new CancelledException();
			}
			long b = bytes.next() & 0xFF;
			long next = (size == SupportedByteSize.CHECKSUM8) ? b
					: b << ((numBytes - 1) - i % numBytes) * 8;
			if (xor) {
				sum ^= next;
			}
			else {
				sum += next;
			}
			i++;
		}

		// Handle carry
		if (carry) {
			long max = (long) Math.pow(2, numBytes * 8);
			while (sum >= max) {
				sum = (sum & (max - 1)) + (sum >> (numBytes * 8));
			}
		}

		// Handle complement
		if (onesComp) {
			sum = ~sum;
		}
		else if (twosComp) {
			sum = -sum;
		}

		checksum = toArray(sum, numBytes);
	}
Computes the checksum with the given options.

@param memory The memory to generate the checksum from.
@param addrSet The addresses over which to generate the checksum.
@param monitor Cancelable task monitor to cancel the computation.
@param xor True if the checksum should allow xor operations.
@param carry True if the checksum should allow carry operations.
@param onesComp True if the checksum should be complemented with a ones complement.
@param twosComp True if the checksum should be complemented with a twos complement.
@throws MemoryAccessException If there was a problem accessing the specified memory.
@throws CancelledException If checksum generation was cancelled.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/checksums/BasicChecksumAlgorithm.java