Results 1 to 14 of 14
Thread: please help! (array-register)
- 03-15-2011, 03:16 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
-
What is it you want the code to do?
String.charAt returns a character element, not an integer, so you'll need to convert "binary.charAt(j)" to an Integer before you store it in your "int[] register" array
- 03-15-2011, 09:46 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
i've already converted a text into binary.what i want the code to do is to place each of binary bits into the register.for example,let the text be "axcbd" and here is the binary for the text --> a= 1010101 , b 1101010 , c = 1110101, d = 1111010, x = 1111101
I want to make this binary (10101011111101111010111010101111010) as an initialization for the register to run.hopefully,anyone here can help me to fix this problem.tq
- 03-15-2011, 10:03 PM #4
So? What do you want us to do about it? If you ask a specific question then you will get a specific answer.
Is your binary String always going to be 200 chars long? If not you will get an IndexOutOfBoundsExceptionJava Code:for(int j = 0; j < 200; j++)
Do you realise that the first line is totally pointless? What ever value is inserted into the array on this line is immediately overwritten by the second line.Java Code:register[j] = binary.charAt(j); register[j] = digit;
-
Ah, i see. But the register is an integer array, so once you get the binary representation of each letter you'll need to convert it into a string as you've done in the bracket:
Once you have a long string of all the numbers you can use String.split(String regex) to cut it after each number into an array, and then cast the array of string-numbers into your int register arrayI want to make this binary (10101011111101111010111010101111010)
-
- 03-15-2011, 10:29 PM #7
and yet still no question
-
but i thought the register was initialised...
Java Code:int[] register = new int[200];
- 03-15-2011, 10:40 PM #9
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
sorry,my mistake.what i need to do to make those register call the each of binary bits and put it in that register?
- 03-15-2011, 10:52 PM #10
That is still a statement. Sticking a question mark on the end doesn't make it a question.
You have a binary String which may be shorter than 200 chars long, so you should loop the length of the String and not hard code it to be 200.
For each char in the String convert it to an int and insert into your array.
Done.
-
First convert your binary to a String.
Java Code:String binaryString = "10101011111101111010111010101111010"; String[] registerString = binaryString.split("(?<=\\G.)"); for (i=0;i<registerString.length;i++) { register[i] = Integer.parseInt(registerString[i]); }
- 03-15-2011, 11:05 PM #12
Using String.split and a regular expression might be overkill in this situation. It can be achieved simply enough with charAt.
-
Anything else would require more logic which is obviously lacking in this case...
- 03-15-2011, 11:18 PM #14
Similar Threads
-
Register content of jTextField
By jeata in forum New To JavaReplies: 3Last Post: 11-19-2010, 09:22 PM -
Oracle Connect thru register driver
By chyrl in forum JDBCReplies: 5Last Post: 05-11-2010, 03:45 PM -
Oracle connection and register
By digioleg in forum New To JavaReplies: 1Last Post: 08-19-2009, 07:43 PM -
Register a callback function in other class
By barts2108 in forum New To JavaReplies: 2Last Post: 11-10-2008, 04:24 PM -
can't register a MySQL driver
By prfalco in forum New To JavaReplies: 4Last Post: 02-03-2008, 11:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks