CyberArmy University | Open Source Institute | CyberArmy Intelligence & Security | CyberArmy Services & Projects

You learn something new everyday (revision)


[Replies] [Reply] [View by Thread] [Help]
[Back To SNEAK Development Forum]

Posted by Cpt SAJChurchey On 2005-03-07 21:37:56
In Reply to I'm evil... Posted by Tr flamebalrog On 2005-03-06 00:27:37

Cpt
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:


Guest:
Subject:
Message:
Signature:
Optional Image Link:
http://

CyberArmy::Forum v0.6
Generated In 0.02309 seconds


About Us | Privacy Policy | Mission Statement | Help