In Java, Why do element of my byte array contain 2 bytes?
<p>I am programming a little Java based Android app that receives a c based unsigned char[] byte array from a Bluetooth chip and streams it into a byte array.</p>

<p>The fact that it is Android and Bluetooth shouldn't matter though, it is just background. But, I am using minimum API 8 if that makes a difference.</p>

<p>The main code is:</p>

<pre><code>InputStream is = socket.getInputStream();
DataInputStream dis = new DataInputStream(is);
byte[] buffer = new byte[1024];
bytesRead = dis.read(buffer, 0, 1024);
</code></pre>

<p>However, when I look at the actual contents of the buffer, I see this:</p>

<pre><code>[0] 15 [0xf] [^O]   
[1] 15 [0xf] [^O]   
[2] 0 [0x0] [^@ (NUL)]  
[3] -119 [137] [0x89] [^É]  
[4] 2 [0x2] [^B]    
[5] 6 [0x6] [^F]    
[6] 26 [0x1a] [^Z]  
[7] -47 [209] [0xd1] [Ñ]    
[8] -1 [255] [0xff] [ÿ] 
[9] 104 [0x68] [h]  
[10]    -1 [255] [0xff] [ÿ] 
[11]    -46 [210] [0xd2] [Ò]    
[12]    -1 [255] [0xff] [ÿ] 
[13]    104 [0x68] [h]  
[14]    -19 [237] [0xed] [í]    
[15]    -128 [128] [0x80] [^À]  
</code></pre>

<p>The above is a copy from the eclipse Expression view set to show </p>

<ol>
<li>Element [#]</li>
<li>Signed int value</li>
<li>If negative, unsigned int value [This value does not appear unless #2 is negative]</li>
<li>Hex value</li>
<li>ASCII value</li>
</ol>

<p>My question is, if this is a byte array, why are some of the Hex values containing 2 bytes. Look at elements 6 through 14, each of them are of the form 0x1a, 0x12, 0xff, etc. The bytes 0 through 5 are all one byte (except for element 3).</p>

<p>I don't think this is an issue from the Bluetooth side because I see the actual code being made, and its an unsigned char[] array, each element is only one byte. Plus, I recall seeing something like this in a previous little project that involved taking data streams from an online API.</p>

<p>How can I ensure the Java array elements contain only 1 byte? And for that matter, I feel like I am not understanding something important about Java since this perplexes me -- how can Java allow a byte array to contain more than one byte per element?</p>
