LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-14-2006, 03:37 AM   #1
mac1234mac
Member
 
Registered: Sep 2005
Posts: 183

Rep: Reputation: 30
how to represent int in binary system in Java?


Hi!

I looked for the answer in Java Tutorial but could not find anything
useful.

Cheers
 
Old 03-14-2006, 03:43 AM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 48
Can't directly; use octal or hexadecimal instead
 
Old 03-14-2006, 03:59 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,482

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Java can both read binary representations of numbers with Integer.parseInt(xxx,2) and write numbers in binary with Integer.toBinaryString(number).
 
Old 03-14-2006, 04:09 AM   #4
mac1234mac
Member
 
Registered: Sep 2005
Posts: 183

Original Poster
Rep: Reputation: 30
reply

So if I want to use for example 00010100 I write
int number = Integer.parseInt(00010100,2)?.
 
Old 03-14-2006, 07:11 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,482

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Almost, you need to use:
Code:
int number = Integer.parseInt("00010100",2);
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding binary numbers in java please help!! trscookie Programming 9 02-28-2006 03:16 PM
invalid types int[int] for array subscript scuzzman Programming 2 11-16-2004 09:34 PM
compile java classes to binary? ludeKing Programming 2 08-15-2004 09:59 AM
Binary search tree insertion in java ksgill Programming 6 02-12-2004 05:11 PM
what does this c represent shanenin Linux - Software 3 10-14-2003 01:45 PM


All times are GMT -5. The time now is 12:29 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration