943,892 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 416
  • Java RSS
Aug 4th, 2009
0

Byte to string issue

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

Java Syntax (Toggle Plain Text)
  1. byte[] b = {(byte)0x8D};
  2. 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).
Similar Threads
Reputation Points: 46
Solved Threads: 0
Light Poster
Anon17 is offline Offline
25 posts
since Jul 2009
Aug 4th, 2009
0

Re: Byte to string issue

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.
Reputation Points: 69
Solved Threads: 48
Posting Whiz in Training
nmaillet is offline Offline
203 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: run j2me programs on ubuntu x64
Next Thread in Java Forum Timeline: drawing rectangle based on combo box values





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC