# Odious number

• July 31st, 2012, 03:55 PM
ahanf
Odious number
hello everyone..i need help with this problem to determine a number whether its odious number or not.. im wondering how to convert a given number to its binary value.. any idea? thanks..
• July 31st, 2012, 04:07 PM
Tjstretch
Re: Odious number
Consider reading the API for what you are attempting to do before requesting help on a public forum.

Integer (Java Platform SE 6)

Short psuedocode
Code :

public static boolean isOdius(int num)
{
binary is the binary representation of the number

counter is 0
for each number in binary
{
if number equals 1
counter is counter plus one
}
return if counter is odd
}

• July 31st, 2012, 04:17 PM
Norm
Re: Odious number
Quote:

how to convert a given number to its binary value.
What format is the number stored in? String or int or ?
What format should the converted number be in?
See the Integer class for useful methods for doing conversions from one format to another.
• August 1st, 2012, 12:23 AM
aesguitar
Re: Odious number
Code java:

String bin = Integer.to______String(12345);
Integer binNum =  Integer.________(___);

Fill in the blanks, if you need to make the binary number beyond Integer.MAX_VALUE, then use a Long, and if you still need more room, use a BigInteger.
• August 1st, 2012, 03:59 AM
ahanf
Re: Odious number
Quote:

Originally Posted by Norm
What format is the number stored in? String or int or ?
What format should the converted number be in?
See the Integer class for useful methods for doing conversions from one format to another.

^int value i guess..here's the question..
In odious number is a nonnegative number that has an odd number of 1s in its binary expansion. The first few odious numbers are therefore 1, 2, 4, 7, 8, 11, 13, 14, 16, 19, ... (Sloane's A000069). Numbers that are not odious are said to be evil numbers.

Determine if a given number is Odious or Evil number..

btw..thanks for the help guys.. seems like i should have check javadoc first..too easy..
• September 5th, 2012, 01:54 PM
lightOfDay
Re: Odious number

aesguitar, what's BigInteger? I've heard of it, but I've never actually looked into it. Please tell me more.
• September 5th, 2012, 03:12 PM
jps
Re: Odious number
Quote:

Originally Posted by lightOfDay

aesguitar, what's BigInteger? I've heard of it, but I've never actually looked into it. Please tell me more.

It is a big integer. Your favorite search engine is a better place to ask that question. Too much information is available already without the cost of volunteer's time.
• September 5th, 2012, 03:15 PM
lightOfDay
Re: Odious number
Jeez, sorry...
• September 5th, 2012, 03:25 PM
jps
Re: Odious number
Quote:

Originally Posted by lightOfDay
Jeez, sorry...

I apologize if that come across rude. :) I did not mean it rude. Just pointing you in the right direction.
• December 10th, 2014, 06:40 AM