Results 1 to 2 of 2
  1. #1
    erakhman is offline Member
    Join Date
    May 2010
    Posts
    14
    Rep Power
    0

    Default Convert String to Binary

    Java Code:
    public class Convert {
    
        public static void main(String[] args) {
        	
        	System.out.println(Integer.parseInt("1010",2));
        }
        
    }
    i try convert String to biner but i think my answer is not correct, because i'm input number 1010 and 1010 is biner number so why result is not 1010.

    Thanks.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by erakhman View Post
    Java Code:
    public class Convert {
    
        public static void main(String[] args) {
        	
        	System.out.println(Integer.parseInt("1010",2));
        }
        
    }
    i try convert String to biner but i think my answer is not correct, because i'm input number 1010 and 1010 is biner number so why result is not 1010.

    Thanks.
    "1010" is the String representation of a number in binary representation; it is 10 decimal which is the default format if you print it. The Integer class has a method that generates String representations in other radixes (which is kind of useless here because you already have the binary String representation to start with).

    kind regards,

    Jos

Similar Threads

  1. Convert Decimal To Binary
    By aspire007 in forum New To Java
    Replies: 8
    Last Post: 08-06-2010, 07:32 AM
  2. Replies: 4
    Last Post: 10-26-2009, 10:17 PM
  3. Convert binary into decimal
    By WarmRegards in forum New To Java
    Replies: 8
    Last Post: 10-18-2009, 02:32 PM
  4. convert binary to images
    By fiqueudrue in forum New To Java
    Replies: 3
    Last Post: 02-12-2009, 09:16 AM
  5. Use recursion to convert binary to...
    By coco in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 07:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •