Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Programmer Certification (OCPJP)
XOR operation and GCD calculation
Amit Goel
Ranch Hand
Posts: 50
posted 23 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
how to calculate gcd of two numbers . like gcd(a,m)=p. how to get p??
h2. how to calcuate xor of two numbers . like q=n(xor)x???
Amit<br /> <br />The Less I have, The more I gain..Off the Beaten Path, I Reign.
Manfred Leonhardt
Ranch Hand
Posts: 1492
posted 23 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Amit,
Use the code below to figure out the GCD.
public int gcd( int i1, int i2 ) { // Find largest of both numbers int largest = Math.max( i1, i2 ); // Find smallest of both numbers int smallest = Math.min( i1, i2 ); // Start by dividing larger number by smallest int mod = largest % smallest; // Start off with assuming the smaller value is the answer. int last = smallest; // Loop until we get no remainder while( mod != 0 ) { // Save the last good value last = mod; // Check for remainder again mod = smallest % mod; } // Return last divider value that resulted in no remainder. return( last ); }
For your second question, I don't understand what you want. You can just go ahead and do it:
byte b = 4 ^ 2;
Regards,
Manfred.
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
The Math behind RSA
Simplifying expressions
mod operator efficiency
Trying to build a simple cache memory
Probability question.
More...