'Translated from FITS Checksum Proposal by Seaman, Pence, and Rots.
Use uint32 literals as a hedge against type promotion to int64.
This code should only be called with blocks of 2880 bytes
Longer blocks result in non-standard checksums with carry overflow
Historically,  this code *was* called with larger blocks and for that
reason still needs to be for backward compatibility.'

def _compute_hdu_checksum(self, data, sum32=0):

    u8 = np.uint32(8)
    u16 = np.uint32(16)
    uFFFF = np.uint32(65535)
    if (data.nbytes % 2):
        last = data[(-1)]
        data = data[:(-1)]
    else:
        last = np.uint32(0)
    data = data.view('>u2')
    hi = (sum32 >> u16)
    lo = (sum32 & uFFFF)
    hi += np.add.reduce(data[0::2], dtype=np.uint64)
    lo += np.add.reduce(data[1::2], dtype=np.uint64)
    if ((data.nbytes // 2) % 2):
        lo += (last << u8)
    else:
        hi += (last << u8)
    hicarry = (hi >> u16)
    locarry = (lo >> u16)
    while (hicarry or locarry):
        hi = ((hi & uFFFF) + locarry)
        lo = ((lo & uFFFF) + hicarry)
        hicarry = (hi >> u16)
        locarry = (lo >> u16)
    return ((hi << u16) + lo)
