• Post Reply Bookmark Topic Watch Topic
  • New Topic

how do i declare an int in binary format?  RSS feed

 
Josh Forrest
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do i declare an int in binary format?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you want to do? Load it with a binary value or print out the result as a binary value?
 
Josh Forrest
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would like to take a binary value and print out it's decimal representation. thanks.
 
Joe Meade
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Integer class has a couple of static methods that handle what you are trying to do:

HTH,
Joe
 
B Stapleton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Update: As of Java 7, you can declare binary numbers with this syntax:

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To avoid any confusion, that syntax in no way changes how the int is stored or how the int is declared. All that notation does is to allow numeric littorals to be expressed as binary number. No mre and no less.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!