Frnds, My questions is "how come to know whether the number is even or odd without using %,/,bitwise operator".
vivekH 0 Light Poster
Recommended Answers
Jump to PostI guess you didn't read the bit about not using %
Jump to PostCan you use shift operators?
Jump to PostThe (definitive) Java Language Spec describes 'bitwize" operators in section 15.22, but shift operators in section 5.19, which to me confirms that shift operators are not "bitwize" operators, so are not forbidden for this exercise.
So: shift your number one bit right, then back 1 bit left again, and if …
Jump to PostShift 1 bit to the right... the rightmost bit will be lost.
Then shift back 1 place to the left and a zero will be used to fill the last bit.A small eg: consider these two numbers (4 bits for simplicity)
0111 (7, an odd number)
0010 (2, an …
Jump to PostInteresting...
You could start by subtracting higher powers of 2 and do that in just thirty passes of the loop. Pseudo-code:
int pot = 2 to the power 30 (hex 40 00 00 00) while (pot >= 2) if (i > pot) i -= pot; pot = …
All 17 Replies
oussama_1 39 Posting Whiz in Training
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
oussama_1 39 Posting Whiz in Training
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
vivekH 0 Light Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
vivekH 0 Light Poster
cgeier 187 Junior Poster
Tarek_2 26 Light Poster
cgeier 187 Junior Poster
TylerD75 0 DaniWeb Newbie
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
cgeier 187 Junior Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Slavi 94 Master Poster Featured Poster
vivekH 0 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.