Result of !(NOT) on integer value stored in an integer?

Can I replace the following:
 
VGA->precalcs.characterwidth = VGA->registers->SequencerRegisters.REGISTERS.CLOCKINGMODEREGISTER.DotMode8?8:9;


With:
1
2
3
4
5
byte characterwidth;
characterwidth = VGA->registers->SequencerRegisters.REGISTERS.CLOCKINGMODEREGISTER.DotMode8;
characterwidth = !characterwidth; //0 or 1 to add!
characterwidth |= 8; //Base of 8 to get 8 or 9!
VGA->precalcs.characterwidth = characterwidth; //Store! 


So any non-0 value becomes 0 and 0 becomes 1? (Used in my VGA emulation)
Last edited on
No. You're assuming that VGA->registers->SequencerRegisters.REGISTERS.CLOCKINGMODEREGISTER.DotMode8 is either 1 or 0.

But the test is checking if it's 0 or 1-254.
VGA->registers->SequencerRegisters.REGISTERS.CLOCKINGMODEREGISTER.DotMode8 is a bitflag of 1 bit (
1
2
3
(...)
byte DotMode8 : 1;
(...)
)

BTW does it matter if it's 0 or 1-254 VS 0 or 1? The result will always be 0 or 1?

(!0)==1
(!(1-255))==0
Last edited on
That's right. The ! operator is a logical operator, so its result will always be 0 or 1.
Topic archived. No new replies allowed.