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

Oh. . . and the changes I made this round


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

Posted by Cpt SAJChurchey On 2005-02-21 19:31:53
In Reply to After running the test cases . . . Posted by Cpt SAJChurchey On 2005-02-21 19:29:29

Cpt
Cpt SAJChurchey


The one-byte ranges were wrong in the if statement . . .
public static String string2Bin(String str){
        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 >= -128 && 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");
                }//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(" ");
             }
             return binaryString.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.14651 seconds


About Us | Privacy Policy | Mission Statement | Help