def get_pt2262_deviceid(device_id, nb_data_bits):
    """Extract and return the address bits from a Lighting4/PT2262 packet."""
    if nb_data_bits is None:
        return
    import binascii
    try:
        data = bytearray.fromhex(device_id)
    except ValueError:
        return None
    mask = 255 & ~((1 << nb_data_bits) - 1)
    data[len(data) - 1] &= mask
    return binascii.hexlify(data)
