title: Android signed int to unsigned int conversion
body: <p>I'm trying to convert a signed decimal to an unsigned decimal, but I don't know how to do that.</p>
  
  <p>The Android device is communicating with another iOS device, and we need to send color codes from one platform to another. Because these platforms has different data types (Java signed data types and iOS unsigned data types) we need to make conversions in order to have the same colors on both sides.</p>
  
  <p>This is what I have made so far:</p>
  
  <pre><code>// Parse and retrieve color code from the backend server
  int unsignedColor = getColorFromBackend();
  
  // Now add an alpha channel 'FF' and make it unsigned color
  int signedColor = toSignedColor(unsignedColor);
  // The signed value is -14701818
  
  // Now try to make the conversion back, from signed to unsigned
  int conversion = toUnsignedColor(signedColor);
  // The value is: 129712 which is not the value I want (2075398)
  
  private int toUnsignedColor(int signedColor) {
     String hex = Integer.toHexString(signedColor);
     hex = hex.substring(2, hex.length() - 1);
     // hex = "1FAB06";
  
     int unsignedInt = Integer.parseInt(hex, 16);
     return unsignedInt;
  }
  
  private int toSignedColor(int unsignedColor) {
     String hexColor = String.format("#%06X", (0xFFFFFFFF &amp; unsignedColor));
     // hexColor = "#FF1FAB06";
     int signedColor = Color.parseColor(hexColor);
     return signedColor;
  }
  
  // This is an example
  private int getColorFromBackend() {
     return 2075398;
  }
  </code></pre>