Re: Binary byte[] buffer to hex byte[] buffer conversion

From: Chris (chris2k01_at_hotmail.com)
Date: 02/18/04

  • Next message: Tom N: "Re: Java JLabel JPanel Graphics etc..."
    Date: Wed, 18 Feb 2004 02:58:08 GMT
    
    

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    GianpieroP wrote:

    > "Chris" <chris2k01@hotmail.com> ha scritto nel messaggio
    > news:UzfYb.18042$Hy3.8786@edtnps89...
    >> Hi,
    >> Or, even more concise, how about a call to
    >> java.lang.{Integer|Long}.toHexString()?
    >>
    >> Heh... don't re-invent the wheel :)
    > Ok! So my class loses one method: "... hexify(byte byValue)" and one
    > member: "HEX". But my "wheel" is useful again because it presents
    > "String hexify(byte[] byArr)" static method. However I'm happy if
    > you offers me another existent "wheel" in substitution of my
    > hexify(byte[] ) method.
    >
    > Bye bye,
    > GianpieroP

    Heh... actually, if working with large values, how about:

    public static String hexify(byte[] data) {
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < data.length; i++) {
                    sb.append(Integer.toHexString(((int) data[i]) & 0xFF));
            }
            return sb.toString();
    }

    The use of StringBuffer is the real point I'm making here, since it's
    more efficient than repeated String concatenations. Also, since
    Integer.toHexString() takes an int, you have to do the casting
    oddness to prevent, say, -1 from turning into 0xFFFFFFFF. Other than
    that, your method and mine are about the same. So that's my 2-cent
    wheel :)

    - --
    Chris
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.2 (GNU/Linux)

    iD8DBQFAMqqQnwjA8LryK2IRAiX5AJ4yBjkHA7uH/iwuPcee5upCBoPjUACfXqYH
    bTDHAQpDgKzGA4/uCERa7sE=
    =z+U/
    -----END PGP SIGNATURE-----


  • Next message: Tom N: "Re: Java JLabel JPanel Graphics etc..."

    Relevant Pages

    • Re: C# Static string appending problem.
      ... built up which is being dumped out when the code executes multiple times. ... VerifyPOLineUnique STARTED ... public static string VerifyPOLineUnique(TypedXmlDocument rootNode, ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: C# Static string appending problem.
      ... VerifyPOLineUnique STARTED ... when I execute it a second time, ... public static string VerifyPOLineUnique(TypedXmlDocument rootNode, ...
      (microsoft.public.dotnet.languages.csharp)
    • GetDirectories throws PathTooLongException
      ... DoWorkEventArgs e, string startDirectoryLongForm, string ... numFiles += CountFilesInDirectory(backgroundWorker, e, ... static extern uint GetLongPathName( ... public static string ToLongPathName ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: How to increment a string?
      ... Heh. ... If I'd studied the Rosetta stone I'd probably translate hieroglyphics, ... And thanks for noting that CTRL-Mousewheel can change fontsize. ... > string containing a non-numeric should be considered. ...
      (alt.comp.lang.borland-delphi)
    • Re: Passing values to a property in C#?
      ... Public Shared Property Settings(ByVal Item As String) As String ... wich are equivalent to default properties in VB.Net. ... public static string Settings ... ClassName is the name of the class the indexer is declared in. ...
      (microsoft.public.dotnet.languages.csharp)