Even or odd: Difference between revisions

Content added Content deleted
(→‎{{header|DWScript}}: Move to correct alphabetical place...)
Line 4,227: Line 4,227:
Z80 Assembly has a few ways of testing if a number is even or odd:
Z80 Assembly has a few ways of testing if a number is even or odd:
===RRC===
===RRC===
A right rotate will set the carry if the register's value is odd and clear it if it's even. This does alter the contents of the register, so only use this method if you don't need to remember the number being tested after getting the results of the test.
A right rotate will set the carry if the register's value is odd and clear it if it's even. This does alter the contents of the register, so only use this method if you don't need to remember the number being tested after getting the results of the test. This is the fastest way the Z80 can test a value for even or odd, but only when testing the accumulator <tt>A</tt>
<lang z80>rrca
<lang z80>rrca
jp nc,isEven</lang>
jp nc,isEven</lang>