DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5458>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5458

toHex method bug

           Summary: toHex method bug
           Product: Struts
           Version: 1.0 Final
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Standard Actions
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Hello.

I want to use toHex method... but it fails.
I'm using Struts 1.0.1 Release Candidate 1.
I didn't find "toHex articles" in Struts mailing lists!

Example (in an Action):

byte[] b = new byte[3];
b[0] = 0x77;
b[1] = 0x07;
b[2] = 0x70;
String s = toHex(b);

right value of s is "770770"       (77 + 07 + 70)
but toHex method returns "77770"   (77 +  7 + 70)
all left-zeros are ignored...            ^ Ignored

Source Code
-----------
toHex method in org.apache.struts.action.Action:
    protected String toHex(byte buffer[]) {

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < buffer.length; i++)
            sb.append(Integer.toHexString((int) buffer[i] & 0xff));
        return (sb.toString());

    }

I typed my own method:
    protected String toHex(byte buffer[]) {

        StringBuffer sb = new StringBuffer();
        String s = null;
        for (int i = 0; i < buffer.length; i++) {
                s = Integer.toHexString((int) buffer[i] & 0xff);
                if (s.length() < 2)
                        s = "0" + s;
            sb.append(s);
          }
        return (sb.toString());
    }

Thanks!!!!!!!!!!!!!!

Marcelo.

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to