Note that there are some explanatory texts on larger screens.

plurals
  1. POJava String conversion to hex
    text
    copied!<p>I am working on a tcp/ip socket listener which listens on port 80 for data that arrives from remote hosts. Now these incoming data are in unreadable format and so i have saved this incoming data as they are in a string initially and then converted this string to a character array and then for every index in the array , I have converted the content to hex. Now the problem is that The data is getting converted to hex alright, but in some places the conversion is not proper and the resulting hex part is 'fffd'. is in the place where the resulting hex should be 'bc'(0xBC), it is 'fffd'(0xFF 0xFD). I am forced to believe that some parts of the incoming data are not being read properly by my java program. Im using BufferefInputStream and InputStreamReader for reading the incoming data and am checking the end of stream in the following way.</p> <pre><code> BufferedInputStream is = new BufferedInputStream(connection.getInputStream()); InputStreamReader isr = new InputStreamReader(is); while(isr.read()!=-1) { ... } </code></pre> <p>where 'connection' is a socket object.</p> <p>The input data that im getting through the socket is #SR,IN-0002005,10:49:37,16/01/2010, $&lt;49X ™™š@(bN>™™šBB ©: 4ä ýÕ 01300>ÀäCåKöA÷Л.</p> <p>The hex conversion that my program does has 'fffd' at many places where other hex values should be. The conversion, though is correct for around 60% of the input string</p> <p>Any pointers on why my resulting hex conversion is not what it should be would be of great help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload