Fix bug that D bit is flipped wrongly