def invert_octet(octet):
    """
    Given a integer in range 0 - 255, return its value with all bits logically
    inverted.

    @param int octet - Integer in range 0 to 255.
                       Values > 255 are masked using 0xFF to force them into the
                       range of 0 to 255.)

    @returns int in range 0 - 255

    """
    # Mask off 'octet' to make sure in range 0 to 255.
    norm_octet = octet & 255

    # Invert the bits in norm_octet
    inv_octet = ~norm_octet + 256

    return inv_octet