Is there any actual difference in performance? Is it faster? (lets say I use it in at least 100 cases in the same program, would it improve my program in terms of speed?)
Is there any reason to use (nr & 1 == 0) over (nr % 2 == 0) to check for parity?
183 Views Asked by Stephan At
1
There are 1 best solutions below
Related Questions in BIT-MANIPULATION
- Understanding ~ Operator
- Getting four bits from the right only in a byte using bit shift operations
- How this bitshift to build the number works?
- A + B without arithmetic operators, Python vs C++
- Faster way of adding negative signed to unsigned
- Setting a bit in hexadecimal number
- reverse a number's bits
- php synatax $b = (6 << 1); clarification
- Turning off a single GPIO pin on ARM9 (LPC3141)
- Toggle a given range of bits of an unsigned int in C
- javascript shifting >32-bit to get 64-bit Int
- Setting bits in a bit stream
- Efficient comparison of small integer vectors
- Perform integer division using multiplication
- Bitwise (Bitshift) operations on 64-bit integers in C++
Related Questions in BITWISE-AND
- Is there any reason to use (nr & 1 == 0) over (nr % 2 == 0) to check for parity?
- Why and 1 ( &1) bitwise operation always return 0 or 1
- Bit Masking in a Cache
- Bit wise 'AND' an array of registers in Verilog
- Would storing my data bitwise make search results faster
- String formatting options
- java & operator with two integers?
- Bitwise AND operation not clear
- OpenCV bitwise_and
- What does the bitwise AND operator & do in this code snippet?
- Decimal Division by left shift
- bitwise-and with HEX and CHAR in C
- Get wrong answer in bitwise and on unsigned int on c?
- What is bitwise OR used here for?
- What does the bitwise operator & do in this example?
Related Questions in PARITY
- Why is the big O runtime of 1D parity checking log(n)?
- How to read raw serial data using Java?
- Is there any reason to use (nr & 1 == 0) over (nr % 2 == 0) to check for parity?
- Does parity check includes start and stop bits on RS-232?
- Windows Serial Communication, Handle Parity bit
- 9 bit protocol on UART in embedded Linux
- Finding characters per sec using asynchronous mode
- How to calculate parity of a 32bits number in assembly?
- are there any advantages for CRC when compared with 2 dimentional parity?
- Uses of the AF, PF in modern asm
- bit parity code needs explanation as to how it works?
- Counting Set Bits. 16-bit assembly parity program
- Blocks are not being finalized in a private network
- How to restart a substrate node
- How authority in Parity Proof of Authority chain choose to mine
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
This question might be more appropriate on Software Engineering Stack Exchange.
If you're using an optimizing compiler chances are any form of
n % <power of two>will get optimized ton & <power of two minus one>anyway, since they are equivalent but on pretty much every architecture I can think of the latter is much more efficient.The former form expresses your intent more clearly, though a lot of developers will recognize
n & 1as a "faster version" ofn % 2.