i'm trying to figure out what is the fastest way to do an odd / even check on numbers i don't know whether there is a mathematical way of achieving this i've heard that the fastest would be checking the last bit in the binary array but i wonder what % does for example

if(b%2!=0) then odd

does % do divisions till it finds the result that's why i ask

thank you in advance

Getting the modulo result is a natural outcome of working out the division.

It's just that when you do x/2, the compiler just looks at a different part of the answer.

How it is actually done I dunno.
But if I would write a routine that does it I would continuously subtract 2 from b until zero or until b<2 and return that value.

ok i have this code

if (b | 0x1) odd(); else even();

but it doesn't seem to work proper with some test files since it alway ends up at odd() what am i doing wrong b is alway an integer and positive what should i change

BTW i think that's the fastest way
thanx

is there any way of just checking the last bit in the binary array of a number

That's what I just told you!
Did you even try it, or just dismiss it?

i am sorry i thought i saw % and not & ok problem solved

This question has already been answered. Start a new discussion instead.