Home arrow static arrow Java Programming [Archive] - Converting Bytes into String
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Converting Bytes into String
This topic has 4 replies on 1 page.

Posts:106
Registered: 9/2/00
Converting Bytes into String  
Aug 3, 2004 8:42 PM



 
Hi Guys,
do u know how to convert bytes into String? Im reading data from a serial port which is in byytes and need to convert it into human readable format. need any inputs or sample code...
thanks,
Sac
 

Posts:2,399
Registered: 10/26/00
Re: Converting Bytes into String  
Aug 3, 2004 9:00 PM (reply 1 of 4)



 
new String(byte[]) ?
 

Posts:2,909
Registered: 13.8.2003
Re: Converting Bytes into String  
Aug 3, 2004 10:33 PM (reply 2 of 4)



 
Use one of the String constructors, but use one which let's you specify encoding...
Check the API.
 

Posts:106
Registered: 9/2/00
Re: Converting Bytes into String  
Aug 3, 2004 11:09 PM (reply 3 of 4)



 
Yes,
I have to encode the Bytes in String Format. I have been able to encode in HexaString but im not sure if its the correct data. Also, there is no one i can ask the guys working on a similar software are no longer there. Im just looking for a sample code to encode the bytes
cheers,
Sachin
 

Posts:5,965
Registered: 5/17/03
Re: Converting Bytes into String  
Aug 4, 2004 12:03 AM (reply 4 of 4)



 
I have to encode the Bytes in String Format. I have
been able to encode in HexaString but im not sure if
its the correct data.

If you just print the bytes (using System.out.println) they come out as numbers between -127 and 128. The bitpattern stored in the byte is interpreted as a two's complement number. Nothing can go wrong. What you see is what you have.
 
This topic has 4 replies on 1 page.