Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > Java

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 03-12-2007, 10:42 AM
bob2000's Avatar
bob2000 bob2000 is offline
Registered User
 
Join Date: Feb 2007
Posts: 10
how to convert binary string to int?

Hi,

I need to know how you convert a binary string into its integer variable type equivelant.

For example,
String s="1001" (which is actually the number 9 in binary base 2)

I want to know how to convert it into an int or long variable type.
Is there a method that will take the binary string ie. "Integer.convertBinaryString()" that will take my binary string and convert it into the Base 10 integer equivelant?

Ive heard of the Integer.Decode() method, but I think it only works for converting base 8 and base 16 strings into the integer equivelant. I dont think it converts base 2 strings into int. Does anyone know how to convert a base 2 number in string form into the base 10 integer equivelant?
Reply With Quote
  #2  
Old 03-13-2007, 08:04 AM
prometheuzz prometheuzz is offline
Registered User
 
Join Date: Jul 2005
Location: the Netherlands
Posts: 128
Code:
String binaryString = "1001";
int base = 2;
int decimal = Integer.parseInt(binaryString, base);
Reply With Quote
  #3  
Old 03-13-2007, 11:24 PM
bob2000's Avatar
bob2000 bob2000 is offline
Registered User
 
Join Date: Feb 2007
Posts: 10
hey, thanx alot man.

I must have some how over looked it in the java API docs if it was there.
Reply With Quote
  #4  
Old 03-14-2007, 04:20 AM
prometheuzz prometheuzz is offline
Registered User
 
Join Date: Jul 2005
Location: the Netherlands
Posts: 128
Quote:
Originally Posted by bob2000
hey, thanx alot man.

I must have some how over looked it in the java API docs if it was there.
They call the base "the radix" in the API docs.
Reply With Quote
  #5  
Old 03-21-2007, 10:50 AM
meghadev meghadev is offline
Registered User
 
Join Date: Mar 2007
Posts: 1
Hello Everybody!!

Prometheuzz.... I thik U cn help me vid my problem.. I have an array of String type...
each index is storing a 32-bit binary String...
I wish to convert it into an Integer array.. I have to use these integer values as pixel values and create an image using these.. M Badly Stuck Up... A binary String like "00001111" when converted to integer returns just "1111" .. How can I conserve these zero's...
as of now I have used both the above mentioned statements.. guide me thru...

Thank You
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
No chintucs Java 2 01-21-2007 05:08 PM
KeyListener not responding lordanki Java 3 04-04-2006 11:13 AM
Fixed-length strings in .NET structures emari .NET 3 10-03-2005 12:57 AM
INSERT for multiple tables with IDENTITY Kay Database 1 07-04-2001 06:18 AM
Trying to print a PDF File from VB Kunal Sharma VB Classic 2 04-25-2000 04:45 PM


All times are GMT -4. The time now is 04:26 AM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.