title: Android Bluetooth and sending an unsigned Hex value
body: <p>I am currently working on a Android application that takes values from a text box and then sends it over bluetooth, all operations are in Hex values.</p>
  
  <p>I have a convertion method that can take the string make give me the unsigned integer for the string, but once i place it in the byte array it becomes signed and the board that receives this cannot do signed hex.</p>
  
  <p>This is how the process works:</p>
  
  <pre><code>//sample string to send
  String toSend = "0BDD";
  
  //sending the byte[] to the board over bluetooth
  btOutputStream.write(SendByteData(toSend));
  
  // --- perform the conversion to byte[] ---
  public static byte[] SendByteData(String hexString)
  {
      byte[] sendingThisByteArray = new byte[hexString.length()/2];
      int count  = 0;
  
      for( int i = 0; i &lt; hexString.length() - 1; i += 2 )
      {
          //grab the hex in pairs
          String output = hexString.substring(i, (i + 2));
  
          //convert the 2 characters in the 'output' string to the hex number
          int decimal = (int)(Integer.parseInt(output, 16)) ;
  
          //place into array for sending
          sendingThisByteArray[count] =  (byte)(decimal);
  
          Log.d(TAG, "in byte array = " + sendingThisByteArray[count]);
          count ++;
      }
  
      return sendingThisByteArray;
  }
  </code></pre>
  
  <p>The issue is as follows:
  When the for for loop runs through the string and picks up "0B" it correctly gives me integer 11; then when the loop runs through "DD" it give me integer 221 which is also correct</p>
  
  <p>When I perform the operation of</p>
  
  <pre><code>sendingThisByteArray[count] =  (byte)(decimal);
  </code></pre>
  
  <p>11 gets correctly placed in sendingThisByteArray[0]
  but for sendingThisByteArray[1] the number 221 gets changed to -35</p>
  
  <p>I know that Java has signed bytes.. is there a way to put/place/change the byte array so i can place and number 221 or any other value higher than 127?</p>
  
  <p>your help is greatly appreciated</p>