I am using apache poi to write excel data.
String colour = "A2C465";
byte[] ret = new byte[3];
for(int i=0; i<3; i++){
ret[i] = (byte)hexToInt(colour.charAt(i * 2), colour.charAt(i*2+1));
}
public int hexToInt(char a, char b){
int x = a < 65 ? a-48 : a-55;
int y = b < 65 ? b-48 : b-55;
return x*16+y;
}
After loop iteration, I get ret = {-94, -60,101}. But the actual RGB code is {162,196,101} (since the conversion from int to byte). Because of this, the color next as different in excel sheet can you help me with this?
source
share