Android Question Inline Java

Discussion in 'Android Questions' started by Jmu5667, Jul 21, 2015.

  1. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Hi

    this code does not compile.

    Code:
    #If JAVA
       public String ByteArrayToHexString(byte [] inarray)
       
         {
       
        int i, j, in;
        String [] hex = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
        String out= "";

        For(j = 0 ; j < inarray.length ; ++j)
           {
        in = (int) inarray[j] & 0xff;
        i = (in >> 4) & 0x0f;
        out += hex[i];
        i = in & 0x0f;
        out += hex[i];
        }
        Return out;
       }
    #End If
    I get the following error:

    upload_2015-7-21_14-18-0.png

    All help appreciated.

    Regards

    John.
     
  2. Informatix

    Informatix Expert Licensed User

    for not For
     
  3. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Thanks, not used to Java syntax, everything is lower case :)
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    BTW, you can use ByteConverter to convert an array of bytes to a hex string.

    It should also be simple to convert this code to B4A (don't use this Java code. It will work very bad with non-small arrays).
     
    lemonisdead and Jmu5667 like this.
  5. Informatix

    Informatix Expert Licensed User

    Erel is right. Your code creates a new string for each "out += ". With a large array, that will be very slow and not memory-efficient. If you want to concatenate a long string, uses a StringBuilder (in Java or in B4A).
     
    Jmu5667 likes this.
  6. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Hi Erel

    I am trying to convert, android.nfc.extra.ID=[B@41ad7298, to the UID as I am experiencing problems with the NFC record reader when I store GPS data and some text in a tag. I have also used a combination of UltraLight & MifareUltralight. with MifareUltralight when reading a page it seems to read for then 4 bytes per page.

    So I am trying to understand the data so I can read it manually.

    We have a project to scan many different tags types and store them in an SQL server so a presentation windows app can display the data.

    Regards

    John.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Use ByteConverter.HexFromBytes to convert the array.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice