views:

58

answers:

1

What would be the best way (ideally, simplest) to convert an int to a binary string representation in Java?

For example, say the int is 156. The binary string representation of this would be "10011100".

+4  A: 
Integer.toBinaryString(int i)
Jack
That's convenient! Is there a similar method for longs?
Tyler
http://java.sun.com/j2se/1.3/docs/api/java/lang/Long.html
Ken Liu
@ttreat31: I don't mean this to sound snarky, but you really should have the documentation (in this case JavaDoc) readily at hand whenever you are programming. You shouldn't have to ask: is their a similar method for longs; it should take for you to look it up than to type the comment.
Software Monkey