One more thing . . . |
||
![]() Cpt SAJChurchey Sorry, it's been a few months since I've sat down to code. . . making minor mistakes here and there . . . Now the space should be printed after each binary representation (sets of 16 bits for UTF-16, and sets of 8 bits for UTF-8). I hope that brings us a little closer to what we're looking for. This is really the first time I've coded in a project this large, and the criticism is keeping me on my toes. I hope nobody is annoyed. StringBuffer binaryString = new StringBuffer();
int strlen = str.length();
for(int i=0;i < strlen;++i){ //faster loop
int decimal = str.charAt(i);
String binary = Integer.toBinaryString(decimal);
if(decimal >= -126 && decimal <= 127){ //UTF-8
//Needs to include the -126 and 127 values
int trailingZeros = 8 - binary.length();
for(int j = 0; j < trailingZeros;++j)
binaryString.append("0");
//The StringBuffer is empty no need to insert()
}//end if
else{ //UTF-16
int trailingZeros = 16 - binary.length();
for(int k = 0;k < trailingZeros;++k)
binaryString.append("0");
}//end else
binaryString.append(binary);
binaryString.append(" "); //Inserts space after binary is added to string
}
return binaryString.toString();
}
Cpt SAJChurchey
C/O of Editorial OSI Staff edit0r OSI Feedback Representative Replies:
|
||
| CyberArmy::Forum v0.6 Generated In 0.02351 seconds |