every odd no. has "1" in its last bit and every even no has "0" (in binary)
eg-
2=0010 ,3=0011
4=0100 ,5=0101....and so on
so just logically "AND" the no with "01H" using instruction [HAVING THAT NO. IN ACCUMULATOR (A)]
ANI 01H
so if the no. is even =>
A=0 (and zero flag is set i.e. "1"
but if the no is odd then => A=1
means zero flag is reset i.e. "0"
so using instruction "JZ"
you can find if the no. if even or odd. :)
"IT IS ALWAYS A ODD"
No. Sum of odd + odd = even Sum of odd + even = odd Sum of even + even = even
an odd numberSubtracting an odd number from an even number will always result in an odd number.
Your question is incomplete. Adding an even number with an odd number will always result in an odd number. Multiplying an even number with an odd number will always result in an even number.
The sum of an odd number and an even number is an odd number.
AND it to 1 and test for zero. All even numbers have 0 in the last bit.
Get number Find modulo 2 of number If the result is zero, number is even Else number is odd
An even number can be divided by 2 evenly. An odd number will have a remainder of 1 when divided by 2.
Lets find out.2 + 3 = 5 (Odd)4 + 7 = 11 (Odd)12 + 13 = 25 (Odd)So it appears that the sum of an even and odd number is an odd number.
An even number can be divided by 2 evenly. An odd number will have a remainder of 1 when divided by 2.
The answer is an odd number.
odd * odd = odd answer even * even = even answer odd * even = even answer
Test the least significant bit of the number. If it is 1, the number must be odd. If it 0 it must be even. To achieve this, place the value in B then use the ANI instruction: ANI 01H Thus if B is 01H, B is odd, otherwise it is even. Works for both positive and negative integers.
"IT IS ALWAYS A ODD"
No. Sum of odd + odd = even Sum of odd + even = odd Sum of even + even = even
if remainder (x/2) = 0 then even else odd
Odd