Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

added odd even number check #125

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

Closed
beast177 wants to merge 8 commits into quicksnip-dev:main from beast177:main
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added usage
  • Loading branch information
beast177 committed Jan 2, 2025
commit d1f218b6e229e0255ed29b528de6e2fedec1b2cc
19 changes: 16 additions & 3 deletions snippets/cpp/math-and-numbers/odd-even-check.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: cpp, number, bitwise, even, odd
description: This code demonstrates the fastest way to check if a number is even or odd using bitwise operations. It's more efficient than using the modulor operator (%) since bitwise operations are performed at the CPU level.
tags: cpp, number, even, odd, bitwise
author: Beast177
description: This code demonstrates the fastest way to check if a number is even or odd using bitwise operations. It's more efficient than using the modulor operator (%) since bitwise operations are performed at the CPU level.
tags: cpp, number, even, odd, bitwise
author: Beast177
---

```cpp
Expand All @@ -11,5 +11,18 @@ bool isEven(int num) {
return !(num & 1);
}

// usage -- [odd-even]

#include <iostream>

int main(){

int num1 = 2;
int num2 = 3;

std::cout << num1 << " is " << (isEven(num1) ? "Even" : "Odd") << "\n"; // output - [Even]
std::cout << num2 << " is " << (isEven(num2) ? "Even" : "Odd") << "\n"; // output - [Odd]
}

```

Loading

AltStyle によって変換されたページ (->オリジナル) /