|
#1
|
||||
|
||||
|
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? |
|
#2
|
|||
|
|||
|
Code:
String binaryString = "1001"; int base = 2; int decimal = Integer.parseInt(binaryString, base); |
|
#3
|
||||
|
||||
|
hey, thanx alot man.
I must have some how over looked it in the java API docs if it was there.
|
|
#4
|
|||
|
|||
|
Quote:
|
|
#5
|
|||
|
|||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |