Ich versuche, eine vorzeichenbehaftete int-Variable in ein 3-Byte-Array und rückwärts zu konvertieren. In der Funktion getColorint konvertiere ich den Int-Wert in das Byte-Array. Das funktioniert gut!Java-Byte-Array zu signierten Int
public byte [] getColorByte(int color1){
byte[] color = new byte[3];
color[2] = (byte) (color1 & 0xFF);
color[1] = (byte) ((color1 >> 8) & 0xFF);
color[0] = (byte) ((color1 >> 16) & 0xFF);
return color;
}
Aber wenn ich versuche, auf denen Integer die Byte-Array zu konvertieren zurück mit der getColorint Funktion:
public int getColorint(byte [] color){
int answer = color [2];
answer += color [1] << 8;
answer += color [0] << 16;
return answer;
}
es funktioniert nur für positive ganzzahlige Werte. Hier
ist ein Screenshot während des Debug:
Mein Eingang int Wert ist -16673281 aber meine Ausgabe int Wert ist .
Kann mir jemand helfen?
Dank :)
http://stackoverflow.com/questions/11981966/byte-array-to-signed-int – floyd