>>DIAGNBYTE = NOT DIAGNBYTE

You have used a logical NOT, which returns 1 or 0. You need to use a bitwise NOT. Try

DIAGNBYTE = ~ DIAGNBYTE