You learn something new everyday (revision) |
||
![]() Cpt SAJChurchey I had no idea you could do that w/ parseInt(). Thanx for that piece of info. The new code is: public static String Bin2Text(String str){
if(str == null || str.matches("[^01\\s]"))
throw new IllegalArgumentException("Please insert binary digits separated by spaces");
str = str.trim();
if(str.length() == 0)
throw new IllegalArgumentException("Please insert binary digits separated by whitespace");
StringTokenizer tokenizedStr = new StringTokenizer(str);
StringBuffer text = new StringBuffer();
while(tokenizedStr.hasMoreTokens()){
String binaryString = tokenizedStr.nextToken();
int bytelen = binaryString.length();
if(bytelen > 16)
throw new IllegalArgumentException("Binary value outside of UTF-16 range");
int intValue = Integer.parseInt(binaryString,2);
char textEquivalent = (char) intValue;
text.append(textEquivalent);
}
return text.toString();
}
Cpt SAJChurchey
C/O of Editorial OSI Staff edit0r OSI Feedback Representative Replies:
|
||
| CyberArmy::Forum v0.6 Generated In 0.02309 seconds |