05-26-2021 02:46 AM
@toojer wrote:
I was doing a quick search and found this stream. I realize it's a few years old.
I think some of the answers are great. The easiest way, in my opinion, to implement this is to do the following.
Depends what you mean with easiest. It involves creating an array of booleans. While not a huge thing, it certainly costs extra performance as a new memory block needs to be allocated, so it's not easiest in terms of CPU load. For that you want to use the solution in Message 4 from Jarrod. And in terms of complexity it is definitely not really more difficult to understand.
05-26-2021 02:47 AM
@Yamaeda wrote:
@toojer wrote:
I was doing a quick search and found this stream. I realize it's a few years old.
I think some of the answers are great. The easiest way, in my opinion, to implement this is to do the following.
Just do an AND 1 and the result is 1 for odds and 0 for evens. 😉 No need to convert the number to a 32 byte array and loop through it.
That will tell you if the number itself is odd or even, but not if the number of bits in the binary representation of the number is odd or even. Someone else already did a similar mistake earlier in the thread.
05-26-2021 06:17 AM
How's this:
05-26-2021 06:35 AM - edited 05-26-2021 06:37 AM
Same issue about creating an array of 8 bytes for the booleans. Not a huge performance hit but it is creating a LabVIEW handle which is a memory manager call, only to throw it away again immediately. Numeric to Boolean array in LabVIEW is even more costly than a Typecast and absolutely not a free operation unless you program in FPGA!!!
05-26-2021 08:00 AM - edited 05-26-2021 08:50 AM
This isn't about whether the number is odd or even, but whether the number of bits in the binary number that are "1" are odd or even.
EDIT: Sorry for responding. Because message #10 that I was responding to was at the bottom of page 1, I didn't see the few threads before mine that were already pointing the out the mistake in message #10.
05-26-2021 08:46 AM
I don't think what you wrote here is correct. This will give the even or odd parity of the 32-bit boolean array. The result of this is the parity bit that you append to the word. Giving the result of the even or odd parity bit.
05-26-2021 08:49 AM
I don't think what you wrote here is correct. This will give the even or odd parity of the 32-bit boolean array. The result of this is the parity bit that you append to the word. Giving the result of the even or odd parity bit.
05-26-2021 02:52 PM
OK, for just an 8-bit number, how about a LUT:
(and this time with a correct label on the output!)
05-26-2021 03:48 PM
@paul_cardinale wrote:
OK, for just an 8-bit number, how about a LUT:
(and this time with a correct label on the output!)
Probably fastest. But will require a 256 byte array for the booleans. You seem to have a high aversion to boolean operations. 😁
05-26-2021 07:08 PM
Divide and conquer is how I roll:
For a little extra speed I will unroll - the loops that is.