Byte to string issue

Reply

Join Date: Jul 2009
Posts: 8
Reputation: Anon17 is on a distinguished road 
Solved Threads: 0
Anon17 Anon17 is offline Offline
Newbie Poster

Byte to string issue

 
0
  #1
Aug 4th, 2009
I need to convert a byte array to a string, and it's working perfectly except for a few values.

  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).
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 83
Reputation: nmaillet is an unknown quantity at this point 
Solved Threads: 18
nmaillet nmaillet is offline Offline
Junior Poster in Training

Re: Byte to string issue

 
0
  #2
Aug 4th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC