I need to convert a byte array to a string, and it's working perfectly except for a few values.

byte[] b = {(byte)0x8D};
String s = new String(b);

Instead of adding the value 8D to the string, it adds the value 3F.

Any ideas why this doesn't work? So far it works for every value excluding 8D (01, CC, FF for example all work).

This is an decoding problem. By passing a byte array into a String constructor, it does not consider the exact value, it uses the default character set of the system (probably UTF-8). Converting it to a character array should fix it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.