i have to get 64-bit from a string.
Eg:
String ss = "Hello fifa world i am coming";
I wish to split the ss into 64-bit each;
how can i do that?
How can i get 64-bit from string?
Started by gandudu, Jun 29 2010 09:05 AM
13 replies to this topic
#1
Posted 29 June 2010 - 09:05 AM
|
|
|
#2
Posted 29 June 2010 - 09:38 AM
Hmm. ASCII is a 8-Bit system, so if you cut the String into 8 pairs of 8 characters, you'll have 64bit parts.
Just an Idea.. Not really sure..
What language do you use?
Just an Idea.. Not really sure..
What language do you use?
#3
Posted 29 June 2010 - 09:50 AM
Java, Netbeans
Can provide with coding example?
Can provide with coding example?
#4
Posted 29 June 2010 - 01:03 PM
Use getBytes function, and then combine each group of 8 using left shifts and the bitwise or operator.
#5
Posted 30 June 2010 - 01:25 AM
abzero, actually i'm new to java.
can you provide the sample coding?
Thanks
can you provide the sample coding?
Thanks
#6
Posted 30 June 2010 - 01:36 AM
Bytes[] stringBytes = str.getBytes();
for(int c=0;c<stringBytes.length;c+=8)
{
long res = (stringBytes[c]<<(64-8) |
stringBytes[c+1] <<(64-16) |
stringBytes[c+2] <<(64-24) |
stringBytes[c+3] <<(64-32) |
stringBytes[c+4] <<(64-40) |
stringBytes[c+5] <<(64-48) |
stringBytes[c+6] <<(64-56) |
stringBytes[c+7]);
//Res contains the packed 64-bit representation of the string.
}
This code will fail if the data doesn't contain a multiple of 8 data items. I havn't tested the code, their might be a better way that one of the good java guys might know.
Edited by abzero, 30 June 2010 - 02:17 AM.
Err off by 4 error
#7
Posted 30 June 2010 - 01:41 AM
abzero, actually i'm new to java.
can you provide the sample coding?
Thanks
can you provide the sample coding?
Thanks
#8
Posted 30 June 2010 - 02:04 AM
i tested with string "12345678"
The output is as below:
an exception is thrown.
The output is as below:
Quote
892745532
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
at testcoding.Main.main(Main.java:23)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
at testcoding.Main.main(Main.java:23)
an exception is thrown.
#9
Posted 30 June 2010 - 02:08 AM
abzero, actually i'm new to java.
can you provide the sample coding?
Thanks
can you provide the sample coding?
Thanks
#10
Posted 30 June 2010 - 02:17 AM
gandudu said:
abzero, actually i'm new to java.
can you provide the sample coding?
Thanks
can you provide the sample coding?
Thanks
You can stop posting this message you've posted it three times now. There was an error in my code, I've edited it so it should not throw with that exception.
#11
Posted 30 June 2010 - 02:18 AM
abzero, actually i'm new to java.
can you provide the sample coding?
Thanks
can you provide the sample coding?
Thanks
#12
Posted 30 June 2010 - 02:24 AM
abzero, actually i'm new to java.
can you provide the sample coding?
Thanks
can you provide the sample coding?
Thanks


Sign In
Create Account


Back to top









