Use BIT_CONVERT to simplify this code