Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## 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..

2. ## 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
```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
}```

3. ## The Following User Says Thank You to Tjstretch For This Useful Post:

ahanf (August 1st, 2012)

4. ## Re: Odious number

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.

5. ## The Following User Says Thank You to Norm For This Useful Post:

ahanf (August 1st, 2012)

6. ## Re: Odious number

```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.

7. ## Re: Odious number

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..

8. ## Re: Odious number

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

9. ## Re: Odious number

Originally Posted by lightOfDay