English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

From this :
Octet: 0>>> 11010100
Octet: 1>>> 10110110
Octet: 2>>> 00011100
Octet: 3>>> 11010100
Octet: 4>>> 11001110
Octet: 5>>> 10000011
Octet: 6>>> 11100000
Octet: 7>>> 11110010
Octet: 8>>> 10110111
Octet: 9>>> 00011001
Octet: 10>>> 10110100
Octet: 11>>> 00001110
Octet: 12>>> 10101111
Octet: 13>>> 11010011
Octet: 14>>> 10100000
Octet: 15>>> 11110000
Octet: 16>>> 01111100
Octet: 17>>> 00001101
Octet: 18>>> 01101010
Octet: 19>>> 10010111
Octet: 20>>> 01000001
Octet: 21>>> 11100111
Octet: 22>>> 00110111
Octet: 23>>> 01001000
Octet: 24>>> 00011100
Octet: 25>>> 00011110
Octet: 26>>> 10101111
Octet: 27>>> 01000001
Octet: 28>>> 11110011
Octet: 29>>> 00110001
Octet: 30>>> 11011010
Octet: 31>>> 11100101

To this:
septet is: 0 >> 1010100
septet is: 1 >> 1101101
septet is: 2 >> 1110010
septet is: 3 >> 0100000
septet is: 4 >> 1101101
septet is: 5 >> 1111001
septet is: 6 >> 0100000
septet is: 7 >> 1110000
septet is: 8 >> 1110010

2006-07-14 22:22:06 · 2 answers · asked by Niversphere 1 in Computers & Internet Software

septet is: 9 >> 1101111
septet is: 10>> 1100110
septet is: 11>> 0100000
septet is: 12>> 1101011
septet is: 13>> 1100001
septet is: 14>> 1101011
septet is: 15>> 1101001
septet is: 16>> 0100000
septet is: 17>> 1100001
septet is: 18>> 1110011
septet is: 19>> 1101011
septet is: 20>> 0100000
septet is: 21>> 1101101
septet is: 22>> 1100101
septet is: 23>> 0100000

........

I have worked out a few but unable to print in a for loop in java. Need help here. Thanks .

2006-07-14 22:24:54 · update #1

2 answers

Three choices, all untested code off the top of my head. CAVEAT RECEPTOR:

{
StringBuilder bitArray = new StringBuilder();
for (int i = 0; i < octetArray.length; i++) {
bitArray.append(octetArray[i]);
}

String bitString = bitArray.toString();
for (int j = 0; j < bitString.length(); j += 7) {
System.out.println("Septet is: " + (j / 7) + " >> " + bitString.substring(j, Math.min(j + 7, bitString.length())));
}
}


---------- or ----------


{
int n = (octetArray.length * 8) / 7 + (octetArray.length % 7 = 0 ? 0 : 1);
int j = 0;
String septet = null;
for (int i = 0; i < n; i++) {
switch (i % 8) {
case 0:
septet = octetArray[j].substring(1, 8) + octetArray[Math.max(j - 1, 0)].substring(0, 0);
j++;
break;
case 1:
septet = octetArray[j].substring(2, 8) + octetArray[j - 1].substring(0, 1);
j++;
break;
case 2:
septet = octetArray[j].substring(3, 8) + octetArray[j - 1].substring(0, 2);
j++;
break;
case 3:
septet = octetArray[j].substring(4, 8) + octetArray[j - 1].substring(0, 3);
j++;
break;
case 4:
septet = octetArray[j].substring(5, 8) + octetArray[j - 1].substring(0, 4);
j++;
break;
case 5:
septet = octetArray[j].substring(6, 8) + octetArray[j - 1].substring(0, 5);
j++;
break;
case 6:
septet = octetArray[j].substring(7, 8) + octetArray[j - 1].substring(0, 6);
j++;
break;
case 7:
septet = octetArray[j].substring(8, 8) + octetArray[j - 1].substring(0, 7);
break;
}
}
}


---------- or ----------


{
int nOctets = octetArray.length;
int nSeptets = (nOctets * 8) / 7 + (nOctets % 7 == 0 ? 0 : 1);
int j = 0;
for (int i = 0; i < nSeptets; i++) {
String septetPart1 = j < nOctets ? octetArray[j].substring(i % 8 + 1, 8) : "";
String septetPart2 = j > 0 ? octetArray[j - 1].substring(0, i % 8) : "";
System.out.println("Septet is: " + i + " >> " + septetPart1 + septetPart2);
if (i % 8 < 7) j++;
}
}

2006-07-19 12:14:54 · answer #1 · answered by BalRog 5 · 1 0

search @ http://www.studyjava.org

2006-07-17 14:01:08 · answer #2 · answered by ihoston 3 · 0 2

fedest.com, questions and answers