Skip to content

EVEN or ODD#2

Open
NovaGod wants to merge 1 commit into
ManoCoder:masterfrom
NovaGod:patch-4
Open

EVEN or ODD#2
NovaGod wants to merge 1 commit into
ManoCoder:masterfrom
NovaGod:patch-4

Conversation

@NovaGod

@NovaGod NovaGod commented Oct 23, 2020

Copy link
Copy Markdown

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