Skip to content

EVEN or ODD #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

EVEN or ODD #2

wants to merge 1 commit into from

Conversation

NovaGod
Copy link

@NovaGod NovaGod commented Oct 23, 2020

We can check whether an integer number is EVEN or ODD without using any Arithmetic or Relational operators.

Here is a simple trick that we can use to check whether number is EVEN or ODD. Using Logical AND (&) operator we can check it, each EVEN number has 0th bit LOW (0) and ODD number has 0th bit HIGH (1).

The statement (number & 0x01) will check that 0th bit is HIGH, if it is HIGH (1) number will be an ODD otherwise number will be an EVEN.

We can check whether an integer number is EVEN or ODD without using any Arithmetic or Relational operators.

Here is a simple trick that we can use to check whether number is EVEN or ODD. Using Logical AND (&) operator we can check it, each EVEN number has 0th bit LOW (0) and ODD number has 0th bit HIGH (1).

The statement (number & 0x01) will check that 0th bit is HIGH, if it is HIGH (1) number will be an ODD otherwise number will be an EVEN.
@NovaGod NovaGod closed this Oct 23, 2020
@NovaGod NovaGod reopened this Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant