0

I have a PDU 0020D83DDC4C0020 converted to bytes and then creating a string object by passing encoding as UTF-16BE, but not displayed as (OK HAND SING).

Code snippet:

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;

public class BytesToString {

    public static void main(String[] args) {

        String pdu = "0020D83DDC4C0020";
        byte[] pdubytes = new BigInteger(pdu, 16).toByteArray();

        try {

            System.out.print("\nUTF-16BE  : ");
            for (byte s : pdubytes) {
                System.out.print(new String(new byte[] { s }, "UTF-16BE"));
            }

            System.out.print("\nUTF-16LE  :  ");
            for (byte s : pdubytes) {
                System.out.print(new String(new byte[] { s }, "UTF-16LE"));
            }


        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}

could you please do needful.

Sudheer D
  • 1
  • 1

0 Answers0